How to use the ProGuard in Android Studio?

后端 未结 6 1840
独厮守ぢ
独厮守ぢ 2020-11-28 19:07

This is my first project in Android Studio, and the code of my apps are not obfuscated. Im using this configuration in build.gradle file:

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 19:41

    Here is Some of Most Common Proguard Rules that you need to add in proguard-rules.pro file in Android Sutdio.

    ButterKnife

     -keep class butterknife.** { *; }
     -dontwarn butterknife.internal.**
     -keep class **$$ViewBinder { *; }
     -keepclasseswithmembernames class * {
            @butterknife.* ;
      }
     -keepclasseswithmembernames class * {
            @butterknife.* ;
      }
    

    Retrofit

     -dontwarn retrofit.**
     -keep class retrofit.** { *; }
     -keepattributes Signature
     -keepattributes Exceptions
    

    OkHttp3

     -keepattributes Signature
     -keepattributes *Annotation*
     -keep class okhttp3.** { *; }
     -keep interface okhttp3.** { *; }
     -dontwarn okhttp3.** 
     -keep class sun.misc.Unsafe { *; }
     -dontwarn java.nio.file.*
     -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 
    

    Gson

     -keep class sun.misc.Unsafe { *; }
     -keep class com.google.gson.stream.** { *; }
    

    Code obfuscation

    -keepclassmembers class com.yourname.models** { ; }
    

提交回复
热议问题