proguard-rules“-dontwarn”不工作(AGP 8.0)

问题描述 投票:0回答:0

更新到 Android Gradle Plugin 8.0 后,在 minifyReleaseAndroidTestWithR8 步骤中出现以下构建时错误:

运行 R8 时检测到缺失类。请添加缺少的类或应用在 C:\Users\... pp uild\outputs\mapping 中生成的额外保留规则 eleaseAndroidTest\missing_rules.txt.

缺少类 io.reactivex.Flowable(引用自:io.reactivex.Flowable io.realm.BaseRealm.asFlowable() 和其他 5 个上下文)

缺少类 io.reactivex.Observable(引用自: io.reactivex.Observable io.realm.RealmList.asChangesetObservable() 和 3 其他情况)

缺少类 java.lang.ClassValue(引用自: java.lang.类值 com.google.common.util.concurrent.FuturesGetChecked$GetCheckedTypeValidatorHolder$ClassValueValidator.isValidClass 和其他 3 个上下文)

据我所知,在 AGP 8.0 之前,缺少类被视为警告,现在它们是错误。所以我将

missing_rules.txt
文件中的规则添加到我的
proguard-rules.pro

-dontwarn io.reactivex.Flowable
-dontwarn io.reactivex.Observable
-dontwarn java.lang.ClassValue

不过,新增的

-dontwarn
规则好像没有效果。我在后续构建中遇到相同的“Missing class”错误。我尝试过清理项目后构建、重启 Android Studio 后构建以及使 Android Studio 的缓存无效后构建。一切都无济于事。

我也试过在每条规则中添加“.**”。我仍然遇到相同的“Missing class”错误。

我的

proguard-rules
文件有另一个
-dontwarn
规则 does 工作:

-dontwarn sun.misc.Cleaner

如果我删除这条规则,我会收到

sun.misc.Cleaner
的缺失类警告(如预期的那样),如果我重新设置该规则,错误就会消失。这似乎表明该问题不是
-dontwarn
规则的根本问题。

如果我禁用

minifyEnabled
,构建完成时没有错误。

三个缺失的 (

io.reactivex
) 类中的两个是从 Realm 类中引用的。不确定这是否重要。

我已经没有什么可以尝试的了,欢迎任何想法/建议。

感谢阅读。


proguard-rules.pro

-dontwarn sun.misc.Cleaner                      # this one works

-dontwarn io.reactivex.Flowable                 # has no effect
-dontwarn io.reactivex.Observable               # has no effect
-dontwarn java.lang.ClassValue                  # has no effect

# don't obfuscate field names of RealmObjects that are imported/exported via JSON
# e.g. design & project, and their sub-ordinate classes
-keep class com.something.model.design.** { <fields>; }
-keep class com.something.model.project.** { <fields>; }

# don't obfuscate the fields in BracingButtonBar's ViewBinding class
-keep class com.something.databinding.BracingButtonBarBinding { <fields>; }
# Without this: BracingButtonBarBinding.class.getDeclaredFields() will not
# return the fields for the CheckImageButtons.
# This breaks BracingButtonBar.getButtons().

# don't obfuscate the fields in FretboardValuesDialog's ViewBinding class
-keep class com.something.databinding.FretboardValuesDialogBinding { <fields>; }
# Without this: will crash when raising the FretboardValuesDialog.

-keepattributes *Annotation*, Exceptions

# retain source file names and line numbers in stack traces
-keepattributes SourceFile, LineNumberTable

# de-obfuscating within inner classes doesn't seem to work, maybe this will help?
-keepattributes InnerClasses
android realm proguard android-r8 android-gradle-plugin-8.0
© www.soinside.com 2019 - 2024. All rights reserved.