如何在Android上使用脱机捆绑包来响应本机项目? [英] How to use offline bundle on android for react native project?
问题描述
如何在android上使用离线捆绑包?
我没有在android上看到有关使用离线捆绑包的文档.
我试图取消注释build.gradle中的代码.
How to use offline bundle on android?
I didn`t see the document about use offline bundle on android.
I tried to uncomment the code in build.gradle.
project.ext.react = [
// the name of the generated asset file containing your JS bundle
bundleAssetName: "index.android.bundle",
// the entry file for bundle generation
entryFile: "index.android.js",
// whether to bundle JS and assets in debug mode
bundleInDebug: false,
// whether to bundle JS and assets in release mode
bundleInRelease: true,
// the root of your project, i.e. where "package.json" lives
root: "../../",
// where to put the JS bundle asset in debug mode
jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
// where to put the JS bundle asset in release mode
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
// where to put drawable resources / React Native assets, e.g. the ones you use via
// require('./image.png')), in debug mode
resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
// where to put drawable resources / React Native assets, e.g. the ones you use via
// require('./image.png')), in release mode
resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
// by default the gradle tasks are skipped if none of the JS files or assets change; this means
// that we don't look at files in android/ or ios/ to determine whether the tasks are up to
// date; if you have any other folders that you want to ignore for performance reasons (gradle
// indexes the entire tree), add them here. Alternatively, if you have JS files in android/
// for example, you might want to remove it from here.
inputExcludes: ["android/**", "ios/**"]
]
但是它没有用.它仍然从服务器上获取JS包.
有什么我想念的吗?
but it didn`t work.It still fetch the JS bundle from the server.
Is there something I missed?
推荐答案
要将JS脱机绑定到android,请首先在相应的项目路径中启动服务器:
For offline bunduling of JS into android, first start the server in respective project path:
- 服务器启动时,打开与项目路径相同路径的下一个终端
-
复制并粘贴以下命令: 在命令propmt中复制和粘贴命令之前,请在项目中将资产文件夹设置为各自的路径
如:
android/app/src/main/assets
- when server start, open next terminal with same path as project path
copy and paste this command: Before you copy and paste command in command propmt, make assets folder in project respective path
as:
android/app/src/main/assets
将此命令粘贴到命令提示符中并运行:
paste this command in command prompt and run:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
- 然后在资产文件夹中将显示为index.android.bundle
- 最后,运行命令:react-native run-android(构建新的脱机apk时无需启动服务器,脱机js文件将帮助您构建apk文件.)
- 最终,现在可以在不同的设备上运行apk了(可以从app/src/build/debug.apk运行apk).
- 有时新创建的apk将在不显示图像的情况下运行,如果应用程序在没有图像的情况下运行,则将特定的图像资源文件夹复制并粘贴到android/app/src/main/assets/(图像源文件夹)
- 重新运行应用程序,因此构建apk已准备就绪,可以运行.
这篇关于如何在Android上使用脱机捆绑包来响应本机项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!