Home » Android » android – GoogleAnalyticsV2 and Proguard

android – GoogleAnalyticsV2 and Proguard

Posted by: admin June 15, 2020 Leave a comment

Questions:

I use Google Analytics V2 library in my project.

When I export signed application package from Eclipse I get following output in Console:

Proguard returned with error code 1. See console
  Warning: com.google.analytics.tracking.android.FutureApis: can't find referenced method 'boolean setReadable(boolean,boolean)' in class java.io.File
  Warning: com.google.analytics.tracking.android.FutureApis: can't find referenced method 'boolean setWritable(boolean,boolean)' in class java.io.File
        You should check if you need to specify additional program jars.
  Warning: there were 2 unresolved references to program class members.
           Your input classes appear to be inconsistent.
           You may need to recompile them and try again.
           Alternatively, you may have to specify the option 
           '-dontskipnonpubliclibraryclassmembers'.
  java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:321)
    at proguard.ProGuard.initialize(ProGuard.java:211)
    at proguard.ProGuard.execute(ProGuard.java:86)
    at proguard.ProGuard.main(ProGuard.java:492)

Here’s my proguard.cfg

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn android.support.**
-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 com.android.vending.licensing.ILicensingService
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-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 enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

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

-keep class com.flurry.** { *; }
-dontwarn com.flurry.**

If I add -dontwarn com.google.analytics.tracking.android.FutureApis to config then I get

    at proguard.ProGuard.main(ProGuard.java:492)
   Proguard returned with error code 1. See console
         You should check if you need to specify additional program jars.
   Unexpected error while evaluating instruction:
     Class       = [android/support/v4/view/AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl]
     Method      = [newAccessiblityDelegateBridge(Landroid/support/v4/view/AccessibilityDelegateCompat;)Ljava/lang/Object;]
     Instruction = [18] areturn
     Exception   = [java.lang.IllegalArgumentException] (Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate]))
   Unexpected error while performing partial evaluation:
     Class       = [android/support/v4/view/AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl]
     Method      = [newAccessiblityDelegateBridge(Landroid/support/v4/view/AccessibilityDelegateCompat;)Ljava/lang/Object;]
     Exception   = [java.lang.IllegalArgumentException] (Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate]))
   java.lang.IllegalArgumentException: Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate])
    at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:287)
    at proguard.evaluation.value.IdentifiedReferenceValue.generalize(IdentifiedReferenceValue.java:65)
    at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:481)
    at proguard.optimize.info.MethodOptimizationInfo.generalizeReturnValue(MethodOptimizationInfo.java:247)
    at proguard.optimize.evaluation.StoringInvocationUnit.generalizeMethodReturnValue(StoringInvocationUnit.java:195)
    at proguard.optimize.evaluation.StoringInvocationUnit.setMethodReturnValue(StoringInvocationUnit.java:126)
    at proguard.evaluation.BasicInvocationUnit.exitMethod(BasicInvocationUnit.java:134)
    at proguard.evaluation.Processor.visitSimpleInstruction(Processor.java:514)
    at proguard.classfile.instruction.SimpleInstruction.accept(SimpleInstruction.java:218)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:753)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:587)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:560)
    at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:264)
    at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:181)
    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:116)
    at proguard.optimize.Optimizer.execute(Optimizer.java:372)
    at proguard.ProGuard.optimize(ProGuard.java:306)
    at proguard.ProGuard.execute(ProGuard.java:115)
    at proguard.ProGuard.main(ProGuard.java:492)

Any hints?

How to&Answers:

I’ve also faced this problem. As there’s no official solution in the GA documentation yet, I made up this set of rules:

-keep class com.google.android.gms.analytics.**
-keep class com.google.analytics.tracking.**
-dontwarn com.google.android.gms.analytics.**
-dontwarn com.google.analytics.tracking.**

This skips obfuscation as well, but that should not be a problem for an external libary..

Answer:

The initial warning indicates that FutureApis invokes File#setReadable(boolean,boolean), which doesn’t exist on the target platform that you have specified for your build (apparently android-8 or older). ProGuard can ignore it, but it will be a problem if that code is ever executed on those older platforms. The documentation of Google Analytics specifies that android-7 is sufficient, so presumably ignoring it is fine.

The unexpected error indicates that V4 support class AccessibilityDelegateCompatIcs$1 extends Android class View$AccessibilityDelegate, which doesn’t exist on the target platform that you have specified for your build (android-13 or older). In this case, ProGuard really needs that class to properly process the code. With an incomplete class hierarchy, the output would be a mess.

You can solve both problems by specifying a more recent build target in project.properties when compiling your release version. The missing classes and methods will be present in the corresponding android.jar, so ProGuard will have all the information it needs. Since these classes are just runtime library classes, used for compilation/optimization/obfuscation, they won’t affect the output.

Answer:

I ran into the same problem – I was able to suppress errors when creating ank for release – but when the application it falls, in those places where the classes to which swearing obfuscator. At the moment I have not solved this problem. What is interesting is that in debage mode when running the application through Eclipse – and it works perfectly.