如何为 android 制作关于 React 本机应用程序的捆绑包
How to make a bundle for android about react native app
我知道我可以 运行 'react-native bundle' 命令为 android 制作一个包,但我不知道如何让我的应用程序使用资源而不是来自开发服务器束。我需要在 iOS 中写下关于 bundle 的路径。我应该为 android.THX.
做什么
根据文档,您可以运行:
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/
如前所述生成您的包,然后:
对于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 时,两者也会自动更改...但我一直在使用它以确保它始终使用捆绑包。
我知道我可以 运行 'react-native bundle' 命令为 android 制作一个包,但我不知道如何让我的应用程序使用资源而不是来自开发服务器束。我需要在 iOS 中写下关于 bundle 的路径。我应该为 android.THX.
做什么根据文档,您可以运行:
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/
如前所述生成您的包,然后:
对于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 时,两者也会自动更改...但我一直在使用它以确保它始终使用捆绑包。