将我们的 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 然后查看其内容时,我们可以看到 bundle 没有被复制。但它正确构建在中间工件中:
$ ./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 应用程序进行比较后发现它!
我有
classpath("com.android.tools.build:gradle:7.1.2")
在 android/build.gradle
但是对于 RN 0.68,您需要完全依赖于 7.0.4 版本,否则 JS 包不会复制到最终的 APK 中。发布 APK 在切换到后现在可以工作了
classpath("com.android.tools.build:gradle:7.0.4")
关于android - 升级到 RN 0.68 后,APK 中缺少 index.android.bundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71847922/