【问题标题】:React Native bundle in release APK is not working发布 APK 中的 React Native 包不起作用
【发布时间】:2019-07-30 21:03:22
【问题描述】:

我是 RN 的新手。我在构建发布 APK 时遇到问题。我正在执行以下步骤:

  1. rm -rf node_modules & npm install
  2. 生成包:

反应原生包

 --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/
  1. cd android & ./gradlew assembleRelease

app/build.gradle:

project.ext.react = [
    entryFile: "index.js",
    bundleInDebug: true,
    bundleInRelease: true,
]

apply from: "../../node_modules/react-native/react.gradle"

....

bundleInRelease 选项似乎无法正常工作。然而 ./gradlew assembleDebug 完美运行!请帮忙!

【问题讨论】:

  • 你只需要使用 assembleRelease。捆绑将自行发生。
  • 我尝试过使用 assembleRelease。但是某些功能不起作用,当我在终端上启动 npm install 时,它运行良好。但是,当我使用 assembleDebug 构建 apk 时,一切正常。
  • “某些功能不起作用”是什么意思?你在保护你的应用吗?
  • 我使用了 'react-native-bitcoinjs-lib' 库,而且,我知道没有 proguard 规则。当我启动调试 APK 时一切正常,但在发布 APK 时出现以下错误:“ECPair 类型的预期属性 '0',得到 k”
  • 我注意到,当我设置 bundleInDebug: false 时,我在调试 apk 中遇到了类似的错误。

标签: react-native react-native-android create-react-native-app


【解决方案1】:

解决了!
我使用了“react-native-bitcoinjs-lib”库,问题是该库没有完全配置。根据文档,为了生成发布 APK,另外,我必须在名为 metro.config.js 的项目中创建文件。并在其中编写了以下代码:

module.exports = {
    transformer: {
      minifierConfig: {
        mangle: {
          keep_fnames: true
        }
      }
    }
  }

现在,一切正常。

【讨论】:

    猜你喜欢
    • 2021-05-27
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2020-10-07
    相关资源
    最近更新 更多