Created
August 20, 2024 03:33
-
-
Save hoangchungk53qx1/fb1b66dba7ab776cf4a4c723e9364288 to your computer and use it in GitHub Desktop.
Popular proguard rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add project specific ProGuard rules here. | |
| # You can control the set of applied configuration files using the | |
| # proguardFiles setting in build.gradle. | |
| # | |
| # For more details, see | |
| # http://developer.android.com/guide/developing/tools/proguard.html | |
| # 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 *; | |
| #} | |
| # Uncomment this to preserve the line number information for | |
| # debugging stack traces. | |
| #-keepattributes SourceFile,LineNumberTable | |
| # If you keep the line number information, uncomment this to | |
| # hide the original source file name. | |
| #-renamesourcefileattribute SourceFile | |
| #### Nav | |
| -keepnames class androidx.navigation.fragment.NavHostFragment | |
| -keepnames class * extends android.os.Parcelable | |
| -keepnames class * extends java.io.Serializable | |
| #### OkHttp, Retrofit and Moshi | |
| -dontwarn okhttp3.** | |
| -dontwarn retrofit2.Platform$Java8 | |
| -dontwarn okio.** | |
| -dontwarn javax.annotation.** | |
| -keepclasseswithmembers class * { | |
| @retrofit2.http.* <methods>; | |
| } | |
| -keepclasseswithmembers class * { | |
| @com.squareup.moshi.* <methods>; | |
| } | |
| -keep @com.squareup.moshi.JsonQualifier interface * | |
| -dontwarn org.jetbrains.annotations.** | |
| -keep class kotlin.Metadata { *; } | |
| -keepclassmembers class kotlin.Metadata { | |
| public <methods>; | |
| } | |
| # 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 | |
| # Keep annotation default values (e.g., retrofit2.http.Field.encoded). | |
| -keepattributes AnnotationDefault | |
| # 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 | |
| # Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. | |
| -dontwarn kotlin.Unit | |
| # Top-level functions that can only be used by Kotlin. | |
| -dontwarn retrofit2.KotlinExtensions | |
| -dontwarn retrofit2.KotlinExtensions$* | |
| # 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> | |
| # Keep inherited services. | |
| -if interface * { @retrofit2.http.* <methods>; } | |
| -keep,allowobfuscation interface * extends <1> | |
| # With R8 full mode generic signatures are stripped for classes that are not | |
| # kept. Suspend functions are wrapped in continuations where the type argument | |
| # is used. | |
| -keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation | |
| # R8 full mode strips generic signatures from return types if not kept. | |
| -if interface * { @retrofit2.http.* public *** *(...); } | |
| -keep,allowoptimization,allowshrinking,allowobfuscation class <3> | |
| # With R8 full mode generic signatures are stripped for classes that are not kept. | |
| -keep,allowobfuscation,allowshrinking class retrofit2.Response | |
| -keepclassmembers class * { | |
| @com.squareup.moshi.FromJson <methods>; | |
| @com.squareup.moshi.ToJson <methods>; | |
| } | |
| -keepclassmembers class com.translate.all.language.translator.voice.ocr.data.remote.response.TranslateResponseV1 { | |
| @com.squareup.moshi.FromJson *; | |
| @com.squareup.moshi.ToJson *; | |
| } | |
| -keepclassmembers class com.example.MyClass { | |
| kotlin.Metadata <fields>; | |
| } | |
| -keepattributes Signature | |
| -keepnames class kotlin.jvm.internal.DefaultConstructorMarker | |
| -keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * { | |
| synthetic <init>(...); | |
| } | |
| -keepclasseswithmembers class * { | |
| @com.squareup.moshi.* <methods>; | |
| } | |
| -keep @com.squareup.moshi.JsonQualifier @interface * | |
| # Enum field names are used by the integrated EnumJsonAdapter. | |
| # values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly | |
| # Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi. | |
| -keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum { | |
| <fields>; | |
| **[] values(); | |
| } | |
| # Keep helper method to avoid R8 optimisation that would keep all Kotlin Metadata when unwanted | |
| -keepclassmembers class com.squareup.moshi.internal.Util { | |
| private static java.lang.String getKotlinMetadataClassName(); | |
| } | |
| # Keep ToJson/FromJson-annotated methods | |
| -keepclassmembers class * { | |
| @com.squareup.moshi.FromJson <methods>; | |
| @com.squareup.moshi.ToJson <methods>; | |
| } | |
| #### Data Models | |
| -keepclassmembers class com.translate.all.language.translator.voice.ocr.data.remote.response.TranslateResponseV1 { | |
| kotlin.Metadata <fields>; | |
| } | |
| #### Java 8 | |
| -keepnames @kotlin.Metadata class j$.time.** | |
| -keepnames @kotlin.Metadata class j$.time.**$* | |
| -keep class j$.time.** { *; } | |
| -keep class j$.time.**$* { *; } | |
| -keepclassmembers class j$.time.** { *; } | |
| -keepclassmembers class j$.time.**$* { *; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment