0

我按照官方指南创建了一个可安装的 Android 应用程序。

但是,当./gradlew installRelease我的 React Fragment 加载后,使用应用程序安装 APK 时会崩溃:

RuntimeException: Could not connect to development server.

我的片段代码看起来像这样,就像集成到 Android教程所建议的那样。

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    mReactInstanceManager = ReactInstanceManager.builder()
            .setApplication(getActivity().getApplication())
            .setBundleAssetName("index.android.bundle")
            .setJSMainModuleName("index.android")
            .addPackage(new MainReactPackage())
            .setUseDeveloperSupport(false) // changes nothing
            .setInitialLifecycleState(LifecycleState.RESUMED)
            .build();
    mReactRootView.startReactApplication(mReactInstanceManager, "HelloWorld", null);
    return mReactRootView;
}

你有什么想法我可能做错了吗?即使 App 打包发布,React Native 是否需要开发服务器?我不敢相信.. 我只想让我的应用程序按原样运行。

4

1 回答 1

0

正如上面评论中提到的@rmevans9,您不需要用于发布或开发模式的开发服务器(然后您正在使用离线捆绑功能)。

您在代码中提到的一个有趣的点:

.setUseDeveloperSupport(false) // changes nothing

如果将其设置为 true,应用程序是否通过连接到本地服务器来工作?如果不是,我的猜测是您正在使用的反应应用程序未注册为您在应用程序调用中使用的“HelloWorld”。

 mReactRootView.startReactApplication(mReactInstanceManager, "HelloWorld", null);

确保名称与您的 react native 应用程序中注册的名称匹配。

于 2016-07-19T16:54:31.663 回答