Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard with google-play-services

I have an Android project (target=Google APIs:17). I'm using Proguard and everything works just fine until I added google-play-services library as a dependency. Now I get the following error:

java.lang.IllegalArgumentException: Value is not a reference value [proguard.evaluation.value.InstructionOffsetValue]
at proguard.evaluation.value.Value.referenceValue(Value.java:97)
at proguard.optimize.evaluation.SimpleEnumUseSimplifier.isPoppingSimpleEnum(SimpleEnumUseSimplifier.java:530)
at proguard.optimize.evaluation.SimpleEnumUseSimplifier.isPoppingSimpleEnum(SimpleEnumUseSimplifier.java:520)
at proguard.optimize.evaluation.SimpleEnumUseSimplifier.visitVariableInstruction(SimpleEnumUseSimplifier.java:229)
at proguard.classfile.instruction.VariableInstruction.accept(VariableInstruction.java:306)
at proguard.optimize.evaluation.SimpleEnumUseSimplifier.visitCodeAttribute(SimpleEnumUseSimplifier.java:131)
at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
at proguard.classfile.ClassPool.classesAccept(ClassPool.java:124)
at proguard.optimize.Optimizer.execute(Optimizer.java:373)
at proguard.ProGuard.optimize(ProGuard.java:306)
at proguard.ProGuard.execute(ProGuard.java:115)
at proguard.ProGuard.main(ProGuard.java:483)

I tried everything and nothing happened :(

Here is my proguard cfg file:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*


-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

-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

-dontwarn android.support.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn com.google.common.collect.Maps

-keepclassmembers class * {
    native <methods>;
}

-keepclassmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclassmembers 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 *;
}

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }

-keepclassmembers class **.R$* {
    public static <fields>;
}

-keep class **.R$*

-keepattributes *Annotation*

-keep class com.tjeannin.apprate.** {
   *;
}


-dump class_files.txt 
-printseeds seeds.txt 
-printusage unused.txt 
-printmapping mapping.txt 

-keep class com.aviary.android.feather.headless.AviaryEffect
-keep class com.aviary.android.feather.headless.media.ExifInterfaceWrapper
-keep class com.aviary.android.feather.headless.moa.Moa
-keep class com.aviary.android.feather.headless.moa.MoaResult
-keep class com.aviary.android.feather.headless.moa.MoaHD
-keep class com.aviary.android.feather.headless.filters.NativeFilterProxy
-keep class com.aviary.android.feather.headless.utils.CameraUtils
-keep class com.aviary.android.feather.headless.gl.GLUtils

-keep class com.aviary.android.feather.opengl.AviaryGLSurfaceView
-keep class com.aviary.android.feather.widget.ScrollerRunnable
-keep class com.aviary.android.feather.library.services.BaseContextService
-keep class it.sephiroth.android.library.imagezoom.easing.Easing
-keep class com.aviary.android.feather.library.external.tracking.TrackerFactory
-keep class com.aviary.android.feather.library.tracking.AbstractTracker

-keep interface com.aviary.android.feather.library.services.IAviaryController
-keep interface com.aviary.android.feather.headless.filters.IFilter
-keep interface com.aviary.android.feather.widget.ScrollerRunnable$ScrollableView

-keep class * extends com.aviary.android.feather.library.tracking.AbstractTracker
-keep class * extends com.aviary.android.feather.headless.filters.IFilter
-keep class * extends com.aviary.android.feather.headless.filters.INativeFilter
-keep class * implements com.aviary.android.feather.library.services.IAviaryController
-keep class * extends com.aviary.android.feather.library.services.BaseContextService
-keep class * implements com.aviary.android.feather.widget.ScrollerRunnable$ScrollableView { *; }
-keep class * implements java.lang.Runnable

-keepclasseswithmembers class * {
    protected <init>( com.aviary.android.feather.library.services.BaseContextService );
}

-keepclasseswithmembers class * {
    public <init>( com.aviary.android.feather.library.services.IAviaryController );
}

-keepclassmembers class com.aviary.android.feather.library.tracking.AbstractTracker { *; }

-keepclassmembers interface it.sephiroth.android.library.imagezoom.easing.Easing { *; }

-keepclassmembers class com.aviary.android.feather.library.external.tracking.TrackerFactory { *; }

-keepclassmembers class * implements it.sephiroth.android.library.imagezoom.easing.Easing { *; }

# This class should not be obfuscated at all
-keepclassmembers class com.aviary.android.feather.headless.moa.MoaResult {
    public java.lang.String inputString;
    public android.graphics.Bitmap inputBitmap;
    public java.lang.String outputString;
    public android.graphics.Bitmap outputBitmap;
    public volatile int active;
    public void cancel();
    public synchronized void execute();
}

# Keep all classes with a native method

-keepclassmembers class * {
   public static native <methods>;
   private static native <methods>;
   static native <methods>;
   private native <methods>;
   native <methods>;
}

-keepattributes Signature

Please help me with this one,

Thanks.

like image 297
Shoham Ben-Har Avatar asked Apr 05 '14 16:04

Shoham Ben-Har


People also ask

What is difference between R8 and ProGuard?

R8 differs from proguard in the following ways: R8 has higher Kotlin language support as compared to proguard. Proguard is mainly used by applications developed using Java. Usually, the R8 compiler is much faster than the proguard compiler.

Is ProGuard necessary for Android?

It reduces the size of the application. It removes the unused classes and methods that contribute to the 64K method counts limit of an Android application. It makes the application difficult to reverse engineer by obfuscating the code.

Does R8 use ProGuard?

R8 configuration files. R8 uses ProGuard rules files to modify its default behavior and better understand your app's structure, such as the classes that serve as entry points into your app's code.


2 Answers

If you use Android Studio, ProGuard directives are included

Note: ProGuard directives are included in the Play services client libraries to preserve the required classes. The Android Plugin for Gradle automatically appends ProGuard configuration files in an AAR (Android ARchive) package and appends that package to your ProGuard configuration. During project creation, Android Studio automatically creates the ProGuard configuration files and build.gradle properties for ProGuard use. To use ProGuard with Android Studio, you must enable the ProGuard setting in your build.gradle buildTypes. For more information, see the ProGuard topic.

Reference: Setting Up Google Play Services

like image 60
Bao Le Avatar answered Oct 04 '22 23:10

Bao Le


You did not include the Google Play Service Proguard exceptions: http://developer.android.com/google/play-services/setup.html#Proguard

like image 24
sagis Avatar answered Oct 05 '22 01:10

sagis