I have an application that uses a library with an external link (that is, the library directory is at the same level as the application, but is not copied inside the application folder). The library refers to the application, and both the library and the application include proguard files. Everything works fine until I build the application. When I built the application, all references to the classes defined in the library were not found - I get the error "I can not find the character ..." with all the imported library classes. As I found, this is because when rebuilding the application, proguard confuses all classes and variables, and therefore the application cannot reference them. I added the following to the build.gradle file:
buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' } debug { minifyEnabled false } }
but it seems that when creating the application, the above is not taken into account (or the building is executed in release mode). If I change the above to the 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 a solution? Can I enable proguard only when creating a signed application?
Here is the proguard library 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 the problem a problem of using proguard both in the library and in the application?
android gradle proguard
ap Jun 13 '15 at 16:25 2015-06-13 16:25
source share