英文:
How to skip bundling during react-native android build
问题
从 0.67
升级到 0.71.7
后,我无法以相同的方式构建 Android。以前,android/app/build.gradle
文件中有一个 bundleInRelease
选项,用于跳过 gradle 构建的捆绑部分:
project.ext.react = [
bundleInRelease: false,
// ...
我会使用 react-native bundle
生成一个捆绑文件,然后 gradlew buildRelease
不会执行任何捆绑操作。由于我们的 CI 设置约束,我想继续以这种方式构建。
升级后,android/app/build.gradle
不允许使用 bundleInRelease
标志:
> 无法为类型为 com.facebook.react.ReactExtension 的扩展名为 'react' 的未知属性 'bundleInRelease'。
我尝试将 entryFile
设置为指向 Android 捆绑文件的文件路径(在 android/app/build.gradle
中):
react {
entryFile = file("src/bundle/assets/index.android.bundle")
// ...
这会导致错误:
> ReferenceError: 未计算文件 /Users/josh/mobile-mobapp/android/app/src/bundle/assets/index.android.bundle 的 SHA-1 (/Users/josh/mobile-mobapp/android/app/src/bundle/assets/index.android.bundle)。
可能的原因:
- 项目中存在符号链接 - watchman 不会跟随符号链接。
- 检查你的 metro.config.js 中的
blockList
,确保它没有排除文件路径。
at DependencyGraph.getSha1 (/Users/josh/mobile-mobapp/node_modules/metro/src/node-haste/DependencyGraph.js:194:13)
at Transformer._getSha1 (/Users/josh/mobile-mobapp/node_modules/metro/src/Bundler.js:26:26)
at Transformer.transformFile (/Users/josh/mobile-mobapp/node_modules/metro/src/DeltaBundler/Transformer.js:108:19)
at Bundler.transformFile (/Users/josh/mobile-mobapp/node_modules/metro/src/Bundler.js:60:30)
我还尝试构建 Android 时排除捆绑任务:
gradlew buildRelease -x createBundleReleaseJsAndAssets
出现错误:
> 无法在任务 ':app:createBundleReleaseJsAndAssets' 完成之前查询列表(interface java.util.Collection, org.gradle.api.internal.provider.AbstractCollectionProperty$CollectingSupplier@68df0a5) 的映射值
有什么方法可以解决这个问题吗?
英文:
Since upgrading react-native from 0.67
to 0.71.7
i'm unable to build android the same way. Previously, android/app/build.gradle
had the bundleInRelease
option to skip bundling as part of the gradle build:
project.ext.react = [
bundleInRelease: false,
// ...
I would use react-native bundle
to produce a bundle file, and then gradlew buildRelease
would not do any bundling. I'd like to continue building this same way due to our CI setup constraints.
After upgrading, the android/app/build.gradle
does not allow the bundleInRelease
flag:
> Could not set unknown property 'bundleInRelease' for extension 'react' of type com.facebook.react.ReactExtension.
I've tried setting the entryFile
to point to the android bundle file (in android/app/build.gradle
):
react {
entryFile = file("src/bundle/assets/index.android.bundle")
// ...
this results in error:
> ReferenceError: SHA-1 for file /Users/josh/mobile-mobapp/android/app/src/bundle/assets/index.android.bundle (/Users/josh/mobile-mobapp/android/app/src/bundle/assets/index.android.bundle) is not computed.
Potential causes:
1) You have symlinks in your project - watchman does not follow symlinks.
2) Check blockList
in your metro.config.js and make sure it isn't excluding the file path.
at DependencyGraph.getSha1 (/Users/josh/mobile-mobapp/node_modules/metro/src/node-haste/DependencyGraph.js:194:13)
at Transformer._getSha1 (/Users/josh/mobile-mobapp/node_modules/metro/src/Bundler.js:26:26)
at Transformer.transformFile (/Users/josh/mobile-mobapp/node_modules/metro/src/DeltaBundler/Transformer.js:108:19)
at Bundler.transformFile (/Users/josh/mobile-mobapp/node_modules/metro/src/Bundler.js:60:30)
Also tried building android excluding the bundling task:
gradlew buildRelease -x createBundleReleaseJsAndAssets
error:
> Execution failed for task ':app:mergeReleaseAssets'.
> Querying the mapped value of list(interface java.util.Collection, org.gradle.api.internal.provider.AbstractCollectionProperty$CollectingSupplier@68df0a5) before task ':app:createBundleReleaseJsAndAssets' has completed is not supported
Any ideas how to do this?
答案1
得分: 1
你可以在react{ ... }
内使用debuggableVariants
。
> debuggableVariants = ["release"]
注意:debuggableVariants是可调试的变体列表。对于那些使用react-native-gradle-plugin的情况,会跳过JS捆绑和资源捆绑。默认情况下只有'debug'。
如果您添加了像lite、prod等口味,您将需要列出您的debuggableVariants。
英文:
You can use debuggableVariants
inside react{ ... }
> debuggableVariants = ["release"]
Note: debuggableVariants is the list of variants that are debuggable. For those react-native-gradle-plugin skip the bundling of the JS bundle and the assets. By default is just 'debug'.
If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论