android - 在我的 AAR 库中使用 ConsumerProguardFiles 并在使用混淆字典时获取未找到的文件

标签 android proguard android-r8

在我的库中,我在release构建类型中使用consumerProguardFiles。我的 proguard 角色是:

-obfuscationdictionary proguard-dictionary.txt
-classobfuscationdictionary proguard-dictionary.txt
-packageobfuscationdictionary proguard-dictionary.txt

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/removal/writeonly,!field/marking/private,!class/merging/*,!code/allocation/variable
-flattenpackagehierarchy
-allowaccessmodification
-renamesourcefileattribute SourceFile
-keepattributes *Annotation*
-keepattributes Signature,MethodParameters,LocalVariableTable,LocalVariableTypeTable
-keepattributes SourceFile,LineNumberTable
-keepattributes Exceptions,InnerClasses

当开发人员在项目中使用我的库(AAR)并获取发布版本并使用 minifyEnabled true 时,找不到 proguard-dictionary.txt:

AGPBI: {"kind":"error","text":"File not found: /Users/USER/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt","sources":[{"file":"/Users/USER
 /.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt"}],"tool":"D8"}
AGPBI: {"kind":"error","text":"File not found: /Users/USER
 /.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt","sources":[{"file":"/Users/USER
 /.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt"}],"tool":"D8"}
AGPBI: {"kind":"error","text":"File not found: /Users/USER
 /.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt","sources":[{"file":"/Users/USER
 /.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt"}],"tool":"D8"}

如何在不使用字典文件的情况下使用-obfuscationdictionary? 或者 我该如何解决这个问题?

最佳答案

提到的所有规则都不应该进入由 consumerProguardFiles 指向的文件,它们看起来应该进入 proguardFiles 的行规则 build 图书馆。另外,除非您有非常特殊的要求,否则请从 proguardFiles 中删除所有 -obfuscationdictionary-classobfuscationdictionary-packageobfuscationdictionary > 建立图书馆将是最好的事情。

consumerProguardFiles 用于库的使用者需要拥有库才能工作的规则。所有这些规则都将进入使用该库的项目的构建中。如果您的库不使用反射,那么很可能根本不需要 consumerProguardFiles

关于android - 在我的 AAR 库中使用 ConsumerProguardFiles 并在使用混淆字典时获取未找到的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56621558/

相关文章:

android - 如何在 Android 中调试远程 AIDL 服务?

java - 在Android应用程序包名称中使用特殊字符

android - 使服务关闭外部 Activity (通过隐式 Intent 创建)

android - 如何在android中添加r8规则?

Android:将布局设置为 View 的背景

java - 压缩/缩小/优化 groovy-all、groovy 2.0.1 进行分发?

android - 什么是最安全,最简单,最通用的proguard配置?

android - Excel 的 Proguard 规则在发布版本上失败 - Android

android - 使用 minifyEnabled true 启动应用程序时 FirebaseInitProvider.onCreate 中的 java.lang.IncompatibleClassChangeError

android - Proguard/R8 规则排除 Assets 文件夹