如何为android做一个关于反应原生app的包

时间:2017-04-10 09:59:56

标签: react-native react-native-android

我知道我可以运行' react-native bundle'命令为android制作一个包,但我不知道如何让我的应用程序使用资源而不是来自dev服务器而是来自bundle。我需要在iOS中编写关于bundle的路径。我该怎么做android.THX。

2 个答案:

答案 0 :(得分:0)

根据文件,你可以运行:

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/

来源:https://github.com/facebook/react-native/blob/master/docs/IntegrationWithExistingApps.md#creating-a-release-build-in-android-studio

答案 1 :(得分:0)

如前所述生成您的包,然后:

对于android :(在MainApplication.java中)

public boolean getUseDeveloperSupport() {
  return false;
  //return BuildConfig.DEBUG;
}

对于iOS :(在AppDelegate.m中)

//debugserver with fallback bundle
//  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
//always bundle
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

我认为在生产模式下构建realease时两者都会自动更改...但我一直在使用它来确保它始终使用该捆绑包。