如何使用 React Native 启用 Proguard?

Dev*_*vAS 2 javascript android react-native react-native-android

我想减少我的 APK 大小我遵循了这些https://facebook.github.io/react-native/docs/signed-apk-android
并运行 ./gradlew bundleRelease 而不是 assembleRelease 但我有错误

任务“:app:transformClassesAndResourcesWithProguardForRelease”执行失败。作业失败,

那么我该如何解决它,我是谷歌,但问题仍然存在!但是如果没有启用 Proguard,它的工作非常好,我得到了 (Aab & .Apk) SO 如何解决它!

我认为这个文件有问题,但我不知道如何配置它!

proguard-rules.pro


# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "APP_NAME",
  "version": "1.12.3",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.4.2",
    "@turf/distance": "^6.0.1",
    "@turf/helpers": "^6.1.4",
    "@turf/invariant": "^6.1.2",
    "@turf/turf": "^5.1.6",
    "firebase-admin": "^8.1.0",
    "firebase-functions": "^3.0.1",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "react": "16.8.6",
    "react-moment": "^0.9.2",
    "react-native": "0.59.8",
    "react-native-app-intro-slider": "^3.0.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-fcm": "^16.2.4",
    "react-native-firebase": "5.3.1",
    "react-native-gesture-handler": "1.2.1",
    "react-native-image-picker": "^0.28.0",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-maps": "^0.24.2",
    "react-native-stars": "^1.1.5",
    "react-native-svg": "^9.3.3",
    "react-native-vector-icons": "^6.4.2",
    "react-navigation": "3.11.0"
  },
  "devDependencies": {
    "@babel/parser": "^7.4.4",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.8.0",
    "jest": "24.8.0",
    "metro-react-native-babel-preset": "0.54.1",
    "react-devtools": "^3.6.1",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}
Run Code Online (Sandbox Code Playgroud)

Ami*_*rji 6

如果您希望在应用程序中使用“react-native-firebase”包时启用 Proguard(android/app/build.gradle 中的 minifyEnabled true),则需要更新您的 proguard 规则。

在 (android/app/proguard-rules.pro) 中添加以下几行:

-keep class io.invertase.firebase.** { *; }
-dontwarn io.invertase.firebase.**
Run Code Online (Sandbox Code Playgroud)

有关更多信息,您可以在第 4 步之前查看https://rnfirebase.io/docs/v5.xx/installation/android。

如果它不起作用,您必须转到您使用的其他软件包的文档,并且必须查找其他首选项,以使它们的设置与启用 Proguard 兼容。