I added Google Play Services library to my application. Everything works fine but size of my apk increase in 4 (!) times from 350KB to 1.6MB. For remove unused classes from Google Play Services library I decide to use ProGuard. But now I can not run project or export it to apk because ProGuard returned error. When I do not use GPS lib I have no problems with export but I can not create apk with this library. I read a lot about this problem but any solution that I found did not help me.
Here is my proguard-project.txt (as recomended here)
-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;
}
Here is my proguard.cng
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-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
#keep all classes that might be used in XML layouts
-keep public class * extends android.view.View
-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.Fragment
#keep all public and protected methods that could be used by java reflection
-keepclassmembernames class * {
public protected <methods>;
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-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
-dontwarn org.htmlcleaner.*
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.ads.** { *;}
and here an error that I obtained after export to apk:
[2014-06-20 23:11:38 - Dictionary] Proguard returned with error code 1. See console
[2014-06-20 23:11:38 - Dictionary] You should check if you need to specify additional program jars.
[2014-06-20 23:11:38 - Dictionary] Unexpected error while performing partial evaluation:
[2014-06-20 23:11:38 - Dictionary] Class = [com/google/android/gms/common/GooglePlayServicesUtil]
[2014-06-20 23:11:38 - Dictionary] Method = [showErrorDialogFragment(ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z]
[2014-06-20 23:11:38 - Dictionary] Exception = [java.lang.IllegalArgumentException] (Can't find any super classes of [com/google/android/gms/common/SupportErrorDialogFragment] (not even immediate super class [android/support/v4/app/DialogFragment]))
[2014-06-20 23:11:38 - Dictionary] java.lang.IllegalArgumentException: Can't find any super classes of [com/google/android/gms/common/SupportErrorDialogFragment] (not even immediate super class [android/support/v4/app/DialogFragment])
[2014-06-20 23:11:38 - Dictionary] at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:299)
[2014-06-20 23:11:38 - Dictionary] at proguard.evaluation.value.IdentifiedReferenceValue.generalize(IdentifiedReferenceValue.java:65)
[2014-06-20 23:11:38 - Dictionary] at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:481)
[2014-06-20 23:11:38 - Dictionary] at proguard.evaluation.Variables.generalize(Variables.java:136)
[2014-06-20 23:11:38 - Dictionary] at proguard.evaluation.TracedVariables.generalize(TracedVariables.java:118)
[2014-06-20 23:11:38 - Dictionary] at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:682)
[2014-06-20 23:11:38 - Dictionary] at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:602)
[2014-06-20 23:11:38 - Dictionary] at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:560)
[2014-06-20 23:11:38 - Dictionary] at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:264)
[2014-06-20 23:11:38 - Dictionary] at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:181)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[2014-06-20 23:11:38 - Dictionary] at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116)
[2014-06-20 23:11:38 - Dictionary] at proguard.optimize.Optimizer.execute(Optimizer.java:372)
[2014-06-20 23:11:38 - Dictionary] at proguard.ProGuard.optimize(ProGuard.java:306)
[2014-06-20 23:11:38 - Dictionary] at proguard.ProGuard.execute(ProGuard.java:115)
[2014-06-20 23:11:38 - Dictionary] at proguard.ProGuard.main(ProGuard.java:492)
maybe something wrong with my local configures...
I tried to -keep
and -dontwarn
different classes but now nothing helped...
Please help me!
Add android-support-v4.jar to your project
If you use Eclipse ADT : You should be referencing a copy of the library Google Play Services that you copied to your development workspace—you should not reference the library directly from the Android SDK directory.
https://developers.google.com/android/guides/setup
I have been facing similar problem and few other with Prograud while generating signed build. After lot of search , finally I am able to resolve my problem. I am sure people have better solution than below one.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt # Project target. target=android-22 android.library.reference.1=../../dev/sdk/extras/google/google_play_services/libproject/google-play-services_lib
-optimizationpasses 2 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers -dontpreverify -dontshrink -verbose -dontwarn org.apache.** -dontwarn org.slf4j.** -dontwarn org.json.* -dontwarn org.mortbay.** -dontwarn org.apache.log4j.** -dontwarn org.apache.commons.logging.** -dontwarn org.apache.commons.logging.** -dontwarn org.apache.commons.codec.binary.** -dontwarn javax.xml.** -dontwarn javax.management.** -dontwarn java.lang.management.** -libraryjars libs/android-support-v13.jar -libraryjars libs/google-play-services.jar -dontwarn android.support.v13.** -keep class android.support.v13.** { *; } -keep interface android.support.v13.app.** { *; } -keep public class * extends android.support.v13.** -keep public class * extends android.app.Fragment -dontwarn com.google.android.gms.** -keep class com.google.android.gms.** { *; } -dontwarn com.google.code.** -dontwarn oauth.signpost.** -dontwarn twitter4j.** -dontwarn com.google.ads.** -dontwarn org.acra.** -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -allowaccessmodification -keepattributes *Annotation* -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable -repackageclasses '' -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 -keep public class com.google.code.linkedinapi.** -keep public class android.content.** { *; } -keep class javax.** { *; } -keep class org.** { *; } -keep class twitter4j.** { *; } -keep class java.lang.management.** { *; } -keep class com.google.code.** { *; } -keep class oauth.signpost.** { *; } -keep class org.acra.** { *; } -keepclassmembers public class com.google.code.linkedinapi.client.impl.LinkedInApiXppClient { public <init>(java.lang.String, java.lang.String); } -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers class **.R$* { public static <fields>; } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep public class * { public protected *; } -keep class * implements android.os.Parcelable { public static final ** CREATOR; }
Best Regards, Vik
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With