将我们的 RN 应用程序升级到 RN 0.68 后,我们在发布版本中遇到错误:
FATAL EXCEPTION: create_react_context
Process: com.app, PID: 15057
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
该应用程序在开发中运行良好,并且在升级之前也运行良好。它使用 Hermes,但没有使用新的 Fabric 架构。
当构建 APK 然后查看其内容时,我们可以看到捆绑包未被复制。但它是正确构建在中间工件中的:
$ ./gradlew assembleRelease
…
BUILD SUCCESSFUL in 45s
1050 actionable tasks: 14 executed, 1036 up-to-date
$ unzip -l app/build/outputs/apk/release/app-arm64-v8a-release.apk | grep bundle
<nothing>
$ ls -l app/build/outputs/apk/release/app-arm64-v8a-release.apk
-rw-r--r-- 1 renchap staff 15618010 Apr 12 21:03 app/build/outputs/apk/release/app-arm64-v8a-release.apk
$ find . -name "index.android.bundle"
./app/build/generated/assets/react/release/index.android.bundle
./app/build/intermediates/merged_assets/release/out/index.android.bundle
./app/build/intermediates/merged_assets/release/mergeReleaseAssets/out/index.android.bundle
./app/build/intermediates/assets/release/index.android.bundle
$ ls -lh ./app/build/intermediates/assets/release/index.android.bundle
-rw-r--r-- 1 renchap staff 11M Apr 12 19:48 ./app/build/intermediates/assets/release/index.android.bundle
我怀疑缺少构建步骤,并且没有将其复制到最终目录,但我对 Gradle 或 RN 的构建过程不够熟悉,无法检查这一点。
您知道什么可能导致此问题,或者在哪里可以解决此问题吗?
在将构建文件与全新的 RN 应用程序进行比较后发现了它!
I had
classpath("com.android.tools.build:gradle:7.1.2")
in android/build.gradle
但对于 RN 0.68,您需要完全依赖于版本 7.0.4,否则 JS 包不会复制到最终的 APK 中。
切换到后,发布 APK 现在可以运行
classpath("com.android.tools.build:gradle:7.0.4")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)