首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >E/ReactNativeJS:未定义不是对象(计算“”b.default.sync“”)

E/ReactNativeJS:未定义不是对象(计算“”b.default.sync“”)
EN

Stack Overflow用户
提问于 2017-02-14 11:14:05
回答 1查看 1.1K关注 0票数 1

将codePush添加到我的项目中时出现错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
import CodePush from "react-native-code-push";

componentDidMount(){
        console.log("CodePush");
        CodePush.sync();
    }

当我运行我的模块时,遇到了这个错误。CodePush未定义。有人知道它出了什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-06 09:12:10

最后,我在MainActivity中添加了一些行,从而解决了这个问题:

代码语言:javascript
复制
@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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42217245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档