如何在React Native中启用Proguard?

3

我想减小我的APK大小 我按照这些步骤https://facebook.github.io/react-native/docs/signed-apk-android
并且运行了./gradlew bundleRelease而不是assembleRelease 但是我得到了错误信息

执行任务':app:transformClassesAndResourcesWithProguardForRelease'时失败。 工作失败,

那么我该如何解决呢?我已经在谷歌上搜索了,但问题依然存在! 但是没有启用Proguard就可以正常工作,并且我得到了(Aab & .Apk),那么怎样才能解决问题呢!

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

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 *;
#}

Package.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"
  }
}
1个回答

10
如果您想在应用程序中使用“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.**

如需了解更多信息,请在第四步之前查看https://rnfirebase.io/docs/v5.x.x/installation/android

如果不起作用,则必须查看您使用的其他软件包的文档,并查找必须完成的其他设置,以使它们的设置与启用Proguard兼容。


1
更新:看起来 rnfirebase v6 不再需要规则了。https://github.com/invertase/react-native-firebase/issues/3770#issuecomment-642232318 - Anh Nguyen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接