gradle - Android Studio proguard handling in multi-library projects -
i have application uses externally referenced library (that is, directory of library in same level application - not copied inside application's folder). library referenced application , both library , application include proguard files. works fine until build application. when built app, referenced classes defined in library not found - 'cannot find symbol class ...) errors on imports of library classes. found, because when rebuilding application, proguard obfuscates classes , variables , therefore application cannot reference them. have added following build.gradle file,
buildtypes { release { minifyenabled true proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-project.txt' } debug { minifyenabled false } }
but seems when building application, above not taken consideration (or building done in release mode). if change above following (i.e., disable proguard in release mode),
buildtypes { release { **minifyenabled false** proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-project.txt' } debug { minifyenabled false } }
the application compiles fine.
is there solution this? can enable proguard when creating signed application?
here library proguard file:
-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -optimizations !method/marking/static -keep public class * extends android.app.activity -keep public class * extends android.app.application -keep public class * extends android.app.service -keep public class * extends android.content.broadcastreceiver -keep public class * extends android.content.contentprovider -keep public class * extends android.app.backup.backupagenthelper -keep public class * extends android.preference.preference -keep public class com.android.vending.licensing.ilicensingservice -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembers class * { public <init>(android.content.context, android.util.attributeset); } -keepclasseswithmembers class * { public <init>(android.content.context, android.util.attributeset, int); } -keepclassmembers class * extends android.app.activity { public void *(android.view.view); } -keepclassmembers enum * { public static **[] values(); public static ** valueof(java.lang.string); } -keep class * implements android.os.parcelable { public static final android.os.parcelable$creator *; } -dontwarn **compathoneycomb -keep class android.support.v4.** { *; } -keep class * extends java.util.listresourcebundle { protected object[][] getcontents(); } -keep public class com.google.android.gms.common.internal.safeparcel.safeparcelable { public static final *** null; } -keepnames @com.google.android.gms.common.annotation.keepname class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.keepname *; } -keepnames class * implements android.os.parcelable { public static final ** creator; } -keep class com.google.android.gms.** { *; } -keep public class com.google.ads.** { public *; } -keep public class com.google.gson.** { public protected *; } -keep public class com.google.ads.internal.** {*;} -keep public class com.google.ads.internal.adwebview.** {*;} -keep public class com.google.ads.internal.state.adstate {*;} -keep public class com.google.ads.mediation.** { public *; } -keep public class com.google.ads.searchads.** {*;} -keep public class com.google.ads.util.** {*;} -keep class com.google.ads.** -dontwarn com.google.ads.** -keepattributes *annotation*
is problem using proguard in both library , application?
after searching found answer. if using external/separate source libraries main project/application, should not use proguard on library modules. instead, replace following,
buildtypes { release { minifyenabled true proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-project.txt' } debug { minifyenabled false } }
with following (in build.gradle of library/libraries):
buildtypes { release { consumerproguardfiles 'proguard-project.txt' } }
where proguard-project.txt file contains proguard rules library project. when building application (either in debug or release mode), compiler take care of rules (in library , in application).
Comments
Post a Comment