Android R8 不混淆类名

标签 android proguard android-r8

在过去的几个小时里,我一直在研究这个,但没有任何运气。无论如何,类名都不会被混淆。这些只是常规类,而不是 Activity 、服务或其他也在 Android list 中的东西(我知道那些不会被混淆)。我在这里想念什么?

enter image description here

Android Gradle Plugin version: 4.0.0
Gradle version: 6.1.1
Android Studio version: 4.0

对于这些版本,R8 should be enabled by default .这是我的 buildType 配置:
buildTypes {
    release {
        //useProguard false // even tried this without luck
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}

这是我的proguard-rules.pro
-ignorewarnings

# --- Glide ---
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

# --- Billing library ---
-keep class com.android.vending.billing.**

# --- Retrofit2 ---
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

# --- TwitterKit ---
#Picasso Proguard Config https://github.com/square/picasso
-dontwarn com.squareup.okhttp.**

# --- GSON ---
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

# --- SciChart ---
# ignore warnings and save classes required for syntax highlighting
-dontwarn java.awt.**
-dontwarn javax.swing.**
-dontwarn syntaxhighlight.**

-keep public class java.awt.** { *; }
-keep public class javax.swing.** { *; }
-keep public class syntaxhighlight.** { *; }
-keep public class prettify.** { *; }

# need to keep these classes and their methods because they are used by resampling code
-keep public class com.scichart.core.model.DoubleValues { *; }
-keep public class com.scichart.core.model.FloatValues { *; }
-keep public class com.scichart.core.model.IntegerValues { *; }
-keep public class com.scichart.data.model.Point2DSeries { *; }

# repack obfuscated classes into single package so it would be hard to find their originall package
-repackageclasses ''
-allowaccessmodification

我检查过但没有提供任何解决方案的类似问题:
  • Android studio 3.4.2 R8 obfuscator does not obfuscate class names, but only java code inside
  • Class no longer obfuscated after upgrading to Android Gradle plugin 3.4.0
  • Android/java: Transition / Migration from ProGuard to R8?
  • 最佳答案

    根据 WorkManager's proguard file ,预计所有扩展 ListenableWorker 的类(及其子类,例如 Worker )被保留。这是因为类的名称是 WorkManager 内部数据库中的唯一键。

    关于Android R8 不混淆类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62400455/

    相关文章:

    android - FirebaseCrashlytics : Error handling uncaught exception & java. util.concurrent.TimeoutException

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

    java - 将 Maven 库中的 android.support.v4.util.ArraySet 替换为 androidx.collection.ArraySet

    android - 等待 AsyncTask 获取数据并在那之后在 UI 线程中做一些事情

    android-studio - 使用 ProGuard 缩小时无法使用 Android Studio 构建 APK

    android - Gradle在proguard之后找不到内部类的符号

    Android复合主键?

    android - 选项菜单操作栏

    android - 使用 proguard 规则排除文件

    android - R8 问题 : Unable to set up Proguard minifyEnabled because of error GC overhead limit exceeded