Hi ,
I am trying to use code push for react native application is Android. But I am getting the below error

I used manual install steps.
"dependencies": {
"react": "^15.3.0",
"react-native": "^0.30.0",
"react-native-code-push": "^1.14.1-beta"
}
I have tried various methods . Can someone please guide me.
Have you tried requiring the dependency instead of importing it:
var codePush = require("react-native-code-push");
This usually only happens when the native part of our plugin is not linked correctly. Could you share your MainApplication.java? Did you follow these plugin configuration steps? https://github.com/Microsoft/react-native-code-push#plugin-configuration-android
package com.tute.codepushdemo;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.microsoft.codepush.react.CodePush;
import java.util.Arrays;
import java.util.List;
/**
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
// 2. Override the getJSBundleFile method in order to let
// the CodePush runtime determine where to get the JS
// bundle location from on each app start
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
```
@Override
protected boolean getUseDeveloperSupport() {
return true;
}
@Override
protected List
// 3. Instantiate an instance of the CodePush runtime and add it to the list of
// existing packages, specifying the right deployment key. If you don't already
// have it, you can run "code-push deployment ls
return Arrays.asList(
new MainReactPackage(),
new CodePush("ZJTOemC_YjYc7OZqFWgKX6AVCNpq4yEgjuq_Z", MainApplication.this, BuildConfig.DEBUG)
);
}
```
};
}
Are your babel transforms colliding? This issue might be related. https://github.com/graphql/graphql-js/issues/414
Does it work if you use require directly like what @ComethTheNerd suggested?
Are you using the es7 decorator features? Do you have this in your .babelrc?
{
"presets": ["react-native-stage-0/decorator-support"]
}
I am not using es7 decorator
Using "require" also didn't work.
Could u share how u instrumented CodePush in index.android.js?
var CodePush = require("react-native-code-push");
class HelloWorld extends React.Component {
componentDidMount() {
CodePush.sync({ updateDialog: { title: "An update is available!" } });
}
render() {
return (
)
}
}
The trace you posted shows u wrapping the "HelloWorld" component with the default exported function, but I don't see that in your code snippet
'use strict';
import React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
var CodePush = require("react-native-code-push");
class HelloWorld extends React.Component {
componentDidMount() {
CodePush.sync({ updateDialog: { title: "An update is available!" } });
}
render() {
return (
)
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
hello: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
AppRegistry.registerComponent('HelloWorld', () => HelloWorld);
This is the whole code. I just posted a snippet earlier.
@ps-swaroop I am unable to reproduce this error from testing the latest bits on NPM. If you would like, I can set up a skype session with you to see what's going on. Feel free to email me at kogoh AT microsoft.com
@geof90 I mailed you few more details. The funny thing is if I create a new project using "react-native init AwesomeProject" everything works fine. Issue occurs every time I try to integrate to an existing project.
@ps-swaroop I got your email, I will follow up with you offline and close this since it seems to be a problem unique to your setup.
I am getting this issue, also. Are you able to please share your solution for others who find their way to this page?
Edit: The solution for me was a combination of a number of things.
Using React Native 0.29.2, react-native-code-push 1.14.1-beta (which uses code-push 1.8.0-beta)
The relevant parts of MainApplication.java at the end of it looked like this:
// import code push
import com.microsoft.codepush.react.CodePush;
// Add CodePush to MainApplication because of React Native >= 0.29.0; for earlier
// versions add to MainActivity (refer to above instructions)
// See https://github.com/Microsoft/react-native-code-push/tree/e717eb024fe9d1810ac21c40c097f7bc165ea5f1#plugin-configuration-android---react-native-v0180
public class MainApplication extends Application implements ReactApplication {
// Define instance variable
private CodePush _codePush;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected String getJSBundleFile() {
// use the API described in <=1.9.0-beta instructions, adjusting for deprecated method
// See https://github.com/Microsoft/react-native-code-push/blob/e717eb024fe9d1810ac21c40c097f7bc165ea5f1/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java
return _codePush.getJSBundleFile("index.android.bundle");
}
@Override
protected List<ReactPackage> getPackages() {
// Set instance variable; pass MainApplication.this as second argument. For React
// Native < 0.29.0, I think you need just this.
_codePush = new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG);
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
// include CodePush in list. Instructions suggest using _codePush.getReactPackage()
// but this is not defined for Code Push 1.8.0-beta.
// See https://github.com/attentiveness/reading/issues/11 for more information
_codePush
);
}
};
}
I had same issue when i was running app in remote device. It got fixed when i ran
react-native run-android and built the package again
@greena13: same as @rakshans1 for me. I had the issue, but then ran react-native run-ios (iOS in my case) and it fixed it.
I'm getting this issue too when running in iOS simulator, I installed with react-native link.
I'm using it as per the instructions:
import React, { Component } from 'react';
var codePush = require('react-native-code-push');
import ContractorNavigator from './navigation/ContractorNavigator';
class App extends Component {
render() {
return (
<ContractorNavigator />
);
}
}
export default codePush(App);
but I'm still getting codePush is not a function
I've tried restarting the packager with --reset-cache and rebuilding the iOS app
I'm also having this issue.
Tried all of the above solutions but can't get it to work.
This is my index.android.js:
import React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
var CodePush = require("react-native-code-push");
let codePushOptions = { checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME };
class HelloWorld extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.hello}>Mudei memo</Text>
</View>
)
}
}
HelloWorld = CodePush(codePushOptions)(HelloWorld);
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
hello: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
AppRegistry.registerComponent('HelloWorld', () => HelloWorld);
And here is MyReactApplication.java:
public class MyReactApplication extends MultiDexApplication implements ReactApplication {
private CodePush _codePush;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected String getJSBundleFile() {
return _codePush.getJSBundleFile();
}
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
_codePush = new CodePush(BuildConfig.CODEPUSH_KEY, MyReactApplication.this, BuildConfig.DEBUG);
List<ReactPackage> packages = new ArrayList<>();
packages.add(new MainReactPackage());
packages.add(_codePush);
return packages;
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
@joaosilva05 - hi!
Sorry for the silence, do you still experiencing the issue? If so, could you please provide me with your versions of react, react-native and react-native-code-push?
I have the same problem.
code-push version: 1.12.6 beta.
react-native version: 0.40 (also didn't work with 0.37 and 0.38).
I tried the RNPM and also the manual guide but it doesn't work.
Here is my relevant code:
const store = configureStore();
registerScreens(store, Provider);
class App extends Component {
constructor(props) {
super(props);
store.dispatch(fetchUserState());
require('./strings/index');
this.startApp();
}
startApp() {
Navigation.startSingleScreenApp({
screen: {
screen: 'app.Group', // unique ID registered with Navigation.registerScreen
navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
navigatorButtons: {} // override the nav buttons for the screen, see "Adding buttons to the navigator" below (optional)
},
drawer: { // optional, add this if you want a side menu drawer in your app
left: { // optional, define if you want a drawer from the left
screen: 'app.NavigationDrawer' // unique ID registered with Navigation.registerScreen转
}
},
passProps: {}, // simple serializable object that will pass as props to all top screens (optional)
animationType: 'slide-down' // optional, add transition animation to root change: 'none', 'slide-down', 'fade'
});
}
}
export default App;
And on my android index.js I only create an instance of App component:
*/
import App from './js/app';
const app = new App();
@MartinMobilize, I've sent you Example app (via email) where I've resolved some integration issues. Most of them have place due to Example app using react-native-navigation module.
The problem here is that the JS file uses module.exports = ... and the typescript definition file expects a exports.default
https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.js#L536
https://github.com/Microsoft/react-native-code-push/blob/master/typings/react-native-code-push.d.ts#L423
currently i'm having to use:
const CodePush = require("react-native-code-push");
or
import * as CodePush from "react-native-code-push";
(CodePush as any).sync(...);
but this breaks type tooling
@rodrigopivi, in case of using NavigationModule it is also important to properly export CodePush package in MainApplication.java file:
@Nullable
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return Arrays.<ReactPackage>asList(
new CodePush(null, MainApplication.this, BuildConfig.DEBUG)
);
}
In case of wrong import we have the situation when NativeCodePush variable is undefined:
let NativeCodePush = require("react-native").NativeModules.CodePush;
https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.js#L8
The same error occurs for me too although on iOS. On android it works just fine. I installed and linked codepush to my ios app multiple times checking each step, but still i am getting the above error. And the log message says "[CodePush] The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly". I am really stuck. Could anyone please help me out
@rahulmishra-goibibo, you've got the log message due to native-site of react-native-code-push Module have not been installed properly:
https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.js#L475
https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.js#L533
Due to you have verified manual installation steps multiple times, it is hard to say what goes wrong, so could you please provide me with minimal version of your app where the issue reproduces, so I would able to investigate it? You could prepare it using our example app.
Not sure if this helps, but I had the same issue: iOS installation looked solid (libCodePush.a added, libz.tbd added, AppDelegate.m updated) but CodePush remained undefined after import and I got the [CodePush] The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly warning.
A Clean of the main project in Xcode, and then re-running react-native run-ios seemed to fix it. :man_shrugging:
Closing this for now, please feel free to reopen or create new one if needed.
cleaning xcode did not work. I'm using rn v .41
Hi @wvicioso, do you still experiencing the issue? If so, could please provide me more info regarding to your project and environment?
@sergey-akhalkov Hi, I am having the same issue, could you please help me?
error: undefined is not an object (evaluating '_reactNativeCodePush2.default.sync')
I used all methods above, but still can not get it resolved.
"react": "15.4.2",
"react-native": "0.42.3",
"react-native-code-push": "1.17.0-beta",
thanks!
Hi @soleilgl, thanks for reaching us. Could you please take a look at this https://github.com/Microsoft/react-native-code-push/issues/790#issuecomment-294148452 and let me know if it helps? Otherwise could you please share full content of MainApplication.java file?
@sergey-akhalkov
Hi, my MainApplication.java file is like:
package com.app;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "app";
}
}
I tried your method but still doesn't work.....
i resolved it by using:
$ react-native link react-native-code-push
thanks!
@soleilgl, got it, thank you!
Hi @sergey-akhalkov , I'm running into the '(0, _reactNativeCodePush2.default) is not a function.' error in iOS only (Android is working properly). I've tried 'var codePush = require("react-native-code-push");' instead of importing, but run into "codePush is not a function. (In 'codePush(AppContainer)', 'codePush' is undefined)" error. Cleaning in XCode and rerunning didn't work either. Also tried manual linking iOS. Any ideas?
Dependencies are as follows:
"react": "15.3.2",
"react-native": "0.37.0",
"react-native-code-push": "1.17.2-beta",
Hi @NedYork, thanks for reaching out to me. This issue most likely means that native side of CodePush SDK has not been configured correctly, you could try to figure out what goes wrong here by using manual installation steps guide. You also could provide me with the minimal version of your app so I can try to figure out the root cause of the issue and help you to fix it.
I had this issue and in my case, I had to downgrade to [email protected].
In my case, I had left the JS server running from the App1 (which had code-push)
react-native init App2
react-native run-android
and then got this same error. wasted an hour.
killed JS server process. phew. everything works now.
I was able to fix this by moving the codePush function call that wraps the root component to index.js rather that exporting it wrapped from the component's definition file.
App.js:
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
class App extends Component<{}> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
var App = codePush(App); //**WRONG! REMOVE THIS STATEMENT**
export default App;
index.js:
import { AppRegistry } from 'react-native';
import MyRootElement from './App';
import codePush from "react-native-code-push";
var root = codePush(App);
AppRegistry.registerComponent('kernelapp', () => root);
this solved the error for me https://github.com/Microsoft/react-native-code-push/blob/master/docs/setup-android.md
Try re-installing react-native run-android after updating react native version.
Im having this issue on iOS, weirdly enough if I run it through Xcode it works fine, but running through react-native run-ios it gives me the same undefined thing
I have the same issue on ios, manual setup solve the issue.
https://github.com/Microsoft/react-native-code-push/blob/master/docs/setup-ios.md#plugin-installation-ios---manual
@huang-xiao-jian Thanks dude. This worked. I had issue with the iOS only.
Hi all!
I have a situation with codepush v5.4.2, react-native v0.57.3 in iOS v11.4.1, Xcode v9.4.2
I followed the manual instructions and I have the same structure as @nodesman mentions.
Here is how it is set up:
class DirectDrinks extends React.Component {
render () {
return (
<Provider store={store}>
<App />
</Provider>
)
}
}
const DirectDrinksContainer = __DEV__ ? DirectDrinks : codePush(DirectDrinks)
AppRegistry.registerComponent('DirectDrinks', () => DirectDrinksContainer)
}
This is the error:
[CodePush] Loading JS bundle from file:///var/mobile/Containers/Data/Application/4ADF3EFD-A35D-4F24-AA38-284DE595DFD1/Library/Application%20Support/CodePush/050d16fa25e1735660f781f94465dae99e21e6c3c3a369c9c979ed83b6156c3b/CodePush/main.jsbundle
2018-11-29 10:07:30.657781+1300 DirectDrinks Rep Staging[443:280490] Task <BA15548B-E059-426D-A822-D008006BDE5F>.<2> finished with error - code: -999
2018-11-29 10:07:30.963 [error][tid:com.facebook.react.JavaScript] undefined is not an object (evaluating 'h.init')
2018-11-29 10:07:30.964970+1300 DirectDrinks Rep Staging[443:280568] undefined is not an object (evaluating 'h.init')
2018-11-29 10:07:30.968 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: undefined is not an object (evaluating 'h.init')
2018-11-29 10:07:30.968070+1300 DirectDrinks Rep Staging[443:280490] Unhandled JS Exception: undefined is not an object (evaluating 'h.init')
2018-11-29 10:07:30.970 [error][tid:com.facebook.react.JavaScript] Module AppRegistry is not a registered callable module (calling runApplication)
2018-11-29 10:07:30.969696+1300 DirectDrinks Rep Staging[443:280568] Module AppRegistry is not a registered callable module (calling runApplication)
2018-11-29 10:07:30.970964+1300 DirectDrinks Rep Staging[443:280490] *** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: undefined is not an object (evaluating 'h.init')', reason: 'Unhandled JS Exception: undefined is not an object (evaluating 'h.init'), stack:
init@725:583
<unknown>@658:787
n@2:553
<unknown>@654:808
n@2:553
<unknown>@653:148
n@2:553
<unknown>@651:381
n@2:553
<unknown>@647:658
n@2:553
<unknown>@641:349
n@2:553
<unknown>@640:79
n@2:553
<unknown>@337:380
n@2:553
<unknown>@336:79
n@2:553
<unknown>@335:79
n@2:553
<unknown>@334:79
n@2:553
<unknown>@328:206
n@2:553
<unknown>@327:79
n@2:553
<unknown>@13:913
n@2:553
<unknown>@12:30
n@2:553
i@2:266
global code@1069:9
'
*** First throw call stack:
(0x18161ad8c 0x1807d45ec 0x10145b7bc 0x101457c3c 0x181622580 0x181501748 0x18150656c 0x10146f5c0 0x1014b6724 0x1014b6480 0x180f0caa0 0x180f0ca60 0x180f169b4 0x180f172fc 0x180f17cc8 0x180f20098 0x18123fe70 0x18123fb08)
libc++abi.dylib: terminating with uncaught exception of type NSException
In __DEV__ no crashes, but when codepush() function executes, it crashes
It was a versioning problem. In the server there was a bundle created with version 5.0.0-beta.
Then we updated code-push to its latest (5.4.2), there must have some big changes that some functions changed. That was the problem, we updated the bundle in server and is ok now!
Most helpful comment
Have you tried requiring the dependency instead of importing it:
var codePush = require("react-native-code-push");