Proguard Error in the Google Play Services Library

I added the Google Play Services application to the application. Everything works fine, but the size of my apk increases 4 (!) Times from 350 KB to 1.6 MB. To remove unused classes from the Google Play Services library, I decided to use ProGuard. But now I can not start the project or export it to apk, because ProGuard returned an 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 I found did not help me.

Here is my proguard-project.txt (as recommended 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 is the error I received after exporting 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 is wrong with my local settings ... I tried -dontwarn and -dontwarn different classes, but now nothing helped ...

Please help me!

+6
source share
4 answers

Add the android-support-v4.jar project to the project

+4
source

If you use Eclipse ADT: you must reference the copy of the Google Play Services library that you copied to the development workspace - you must not reference the library directly from the Android SDK.

https://developers.google.com/android/guides/setup

+2
source

I ran into a similar problem, and several others with Prograud, when creating a signed assembly. After a lot of searching, finally I can solve my problem. I am sure that people have a better solution than lower.

  • Keep the latest SDKs and supported libraries.
  • Create the "libs" folder inside "/ sdk / tools / progaurd /".
  • Copy the .jar files, for example, "android-support-v13.jar", "google-play-services.jar", which your application needs in the folder "/ sdk / tools / progaurd / libs /".
  • Copy the .jar file to the "libs" application folder. Also remove "android-support-v4.jar" since it is not required, here v13 already supports v4
  • Add the .jar file to your build path. Also remove "android-support-v4.jar" from the build path, since it is not required, here v13 already supports v4.
  • Add lines to the project.properties application file. Please save the target as "android-22".
 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 
  1. My Progaurd file is "proguard-android.txt". Please modify it according to your requirements.
 -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

+1
source

even though I had google play services as a library, I still had to manually add android-support-v4.jar to my libs folder and right-click and add the build path to eclipse.

my proguard file looked like this:

  -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontwarn com.google.** -dontpreverify -dontwarn android.support.v4.** -dontwarn org.apache.commons.codec.binary.Base64 -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -keep class !mycode.** { *; } 

the last line makes only my code get confused. Its cleaner.

0
source

Source: https://habr.com/ru/post/971120/


All Articles