android - 升级到 RN 0.68 后,APK 中缺少 index.android.bundle

标签 android react-native gradle

将我们的 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/

相关文章:

android - 如何在 Android 中实现分页 ListView

android - Dagger 2 和 Android Annotations 可以一起工作吗?

android - 从其 Activity 启动的服务是否在新线程中运行?

javascript - 检索设备信息 React-Native iOS

eclipse - 将现有 Gradle Git 项目导入 Eclipse

Android SDK - 列出蓝牙配置文件

android - react native 使用 debounce 在 android 设备上不起作用

react-native - 为什么高度不会自动调整到宽度?

android - 来自 androidx.core :core:1. 0.0 和 com.android.support :support-compat:26. 1.0 的重复类

gradle - Gradle CustomTask不考虑依赖的InputFiles