Android studio 1.1.0 setting minifyEnabled true causing issues with app

前端 未结 2 1068
青春惊慌失措
青春惊慌失措 2021-02-05 18:56

Here\'s my gradle.build file

defaultConfig {

    minSdkVersion 15
    targetSdkVersion 21
    versionCode 2
    versionName \"1.0\"
}
buildTypes {
    release {         


        
2条回答
  •  执笔经年
    2021-02-05 19:16

    Proguard doesn't play well with many of the libraries I used in my project.

    For gson I added the proguard rules given by the gson team at http://google-gson.googlecode.com/svn/trunk/examples/android-proguard-example/proguard.cfg

    You need to change

    -keep class com.google.gson.examples.android.model.** { *; }
    

    to

    -keep class com.your.package.name.your.models.** { *; }
    

    For retrofit you need to add

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

    Taken from here https://github.com/square/retrofit/issues/117

    For joda library I added

    -keep class org.joda.time.** { *; }
    -dontwarn org.joda.time.**
    

    For otto you need to add

    -dontwarn com.squareup.**
    -keepclassmembers class ** {
        @com.squareup.otto.Subscribe public *;
        @com.squareup.otto.Produce public *;
    }
    

    Taken from here https://github.com/StephenAsherson/Android-OttoSample/blob/master/proguard-project.txt

    I also added

    -keep class com.squareup.okhttp.** { *; }
    

    Before using these configuration changes proguard trimmed my app from 3.4 mb to 2 mb. After using these changes it shrinks it to 3.2 mb so I am just going to go with minifyEnabled false.

提交回复
热议问题