将codePush添加到我的项目中时出现错误:
E/ReactNativeJS: undefined is not an object (evaluating 'b.default.sync')当我将新的react项目与模块应用程序一起使用时,按照文档中的https://github.com/Microsoft/react-native-code-push/blob/master/docs/setup-android.md说明安装代码推送
百事大吉。
但是,当我将代码推送添加到我现有的项目中时,模块名为"passenger",而不是"app",我遵循文档中的步骤,添加代码推送手册。
还要将代码添加到index.android.js中
import CodePush from "react-native-code-push";
componentDidMount(){
console.log("CodePush");
CodePush.sync();
}当我运行我的模块时,遇到了这个错误。CodePush未定义。有人知道它出了什么问题吗?
发布于 2017-06-06 09:12:10
最后,我在MainActivity中添加了一些行,从而解决了这个问题:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("main.bundle")
.setJSMainModuleName("TingBadgeManager")
.addPackage(new SQLitePluginPackage())
.addPackage(new CodePush("xxx", getApplicationContext(), com.xxx.xxx.BuildConfig.DEBUG)) // register CodePush Plugin here
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(true)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "TingBadgeManager", null);
setContentView(mReactRootView);
}关键点是,如果您在活动中创建RN,则应在mReactInstanceManager中添加带有addPackage的CodePush。希望这能有所帮助。
相关问题:https://github.com/Microsoft/react-native-code-push/issues/871
https://stackoverflow.com/questions/42217245
复制相似问题