【问题标题】:Android Studio is generating very old apk for react-native project like 3 months oldAndroid Studio 正在为 3 个月大的 react-native 项目生成非常旧的 apk
【发布时间】:2020-03-01 09:33:00
【问题描述】:

Android Studio 正在为 3 个月大的 react-native 项目生成非常旧的 apk。但是运行这个命令“react-native run-android”时在模拟器中完美运行

过程 - * 打开文件所在位置 * 构建 => 构建捆绑包 => 构建 APK

尝试重新安装 android studio 但还是老 APK

【问题讨论】:

  • 这是因为android平台使用的bundle是旧的

标签: android react-native android-studio


【解决方案1】:

在旧的 react-native 版本中,当我们生成 android APK 时,有时 bundle 是旧的,我们必须自己生成。
在 react-native 0.61 中,我发现问题被忽略了。 在旧版本中,首先您应该将以下脚本添加到 package.json

"scripts":{
...
"bundle-android": "react-native bundle --entry-file index.js  --platform android --dev false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res",
...
}

当你生成apk时,你首先在termail中运行下面的脚本来生成新的bundle

npm run bundle-android

当bundle输出成功后,进入android目录组装APK

cd android

./gradlew assembleRelease

【讨论】:

    【解决方案2】:
    react-native bundle --platform android --dev false --entry-file index.js -- 
    bundle-output android/app/src/main/assets/index.android.bundle --assets-dest 
    android/app/src/main/res/
    

    如果您收到重复资源的错误,请转到 res 文件夹并仅删除 drawable-hdpi、drawable-mdpi、drawable-xhdpi、drawable-xxhdpi、drawable-xxxhdpi 文件夹并尝试重建项目。它会起作用的。

    【讨论】:

      【解决方案3】:

      这是因为,你有旧的 index.android.bundle 文件。按照以下步骤更新此文件并创建一个新的 apk:

      1. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
      2. curl "http://localhost:8081/index.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
      3. cd android && ./gradlew clean assembleDebug

      【讨论】:

        猜你喜欢
        • 2022-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-14
        • 2021-06-05
        相关资源
        最近更新 更多