It so fell out that I use jacorb.jar and CORBA interfaces in my android app. And when I try obfuscate code using Proguard I get a lot of warnings like this one:
[proguard] Warning: org.jacorb.orb.standardInterceptors.SASComponentInterceptor: can't find referenced
class org.ietf.jgss.Oid
And as the result:
[proguard] Warning: there were 1223 unresolved references to classes or interfaces.
[proguard] You may need to specify additional library jars (using '-libraryjars'),
[proguard] or perhaps the '-dontskipnonpubliclibraryclasses' option.
[proguard] Warning: there were 33 unresolved references to program class member
s.
[proguard] Your input classes appear to be inconsistent.
[proguard] You may need to recompile them and try again.
[proguard] Alternatively, you may have to specify the options
[proguard] '-dontskipnonpubliclibraryclasses' and/or
[proguard] '-dontskipnonpubliclibraryclassmembers'.
My proguard.cfg :
-injars bin/classes
-outjars bin/classes-processed.jar
-libraryjars C:/android-sdk-windows/platforms/android-7/android.jar
-libraryjars libs
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontnote
-keep class com.android.vending.billing.**
-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.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
How to correct these warnings and build working apk file?
Cfr. ProGuard manual > Troubleshooting > Warning: can't find superclass or interface.
Jacorb appears to depend on JGSS, which is not part of the Android runtime. In theory, JGSS should be specified as a library package. However, since your app already runs fine without JGSS, it's fair to assume that this part of the code is never used. You can then switch off the warnings:
-dontwarn org.ietf.jgss.**
ProGuard will no longer complain about these missing classes and proceed with processing the code. The summary in your console output suggests that there are many classes that are probably similar.
Related
I have created app using Cling and is working fine but when I create release build I get following message and nothing plays on renderer:
11-22 16:24:53.341 20172-20172/? I/RendererCommand﹕ TrackMetadata : TrackMetadata [id=1, title=IMG-20151120-WA0007, artist=, genre=, artURI=res=http://192.168.1.4:8089/1.jpg, itemClass=object.item.imageItem]
11-22 16:24:53.345 20172-20172/? V/RendererCommand﹕ Resume
11-22 16:24:53.351 20172-20301/? W/RendererCommand﹕ Fail to stop ! Error: Current state of service prevents invoking that action. Error writing request message. Can't transform message payload: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType. (HTTP response was: 500 Internal Server Error)
11-22 16:24:53.351 20172-20301/? I/RendererCommand﹕ Set uri to http://192.168.1.4:8089/1.jpg
11-22 16:24:53.353 20172-20386/? D/RendererCommand﹕ Update state !
11-22 16:24:53.354 20172-20264/? W/RendererCommand﹕ Fail to set URI ! Error: Current state of service prevents invoking that action. Error writing request message. Can't transform message payload: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType. (HTTP response was: 500 Internal Server Error)
11-22 16:24:53.354 20172-20262/? W/RendererCommand﹕ Fail to get position info ! Error: Current state of service prevents invoking that action. Error writing request message. Can't transform message payload: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType. (HTTP response was: 500 Internal Server Error)
11-22 16:24:54.354 20172-20386/? D/RendererCommand﹕ Update state !
Below is my proguard enteries:
-dontoptimize
-dontshrink
-dontskipnonpubliclibraryclasses
-dontpreverify
-allowaccessmodification
-verbose
-dontwarn org.fourthline.cling.**
-dontwarn org.seamless.**
-dontwarn org.eclipse.jetty.**
-dontwarn android.support.v4.app.**
-dontwarn android.support.design.widget.**
-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 class javax.** { *; }
-keep class org.** { *; }
-keep class org.fourthline.cling.** { *;}
-keep class org.seamless.** { *;}
-keep class org.eclipse.jetty.** { *;}
-keep class org.slf4j.** { *;}
-keep class javax.servlet.** { *;}
-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 *;
}
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keepattributes *Annotation*
Ok after having reading proguard manual, and having numerous hit and trials I finally did it by modifying last line of above prguard file to
-keepattributes Annotation, InnerClasses, Signature
and every thing works fine
from proguard
Specifies the generic signature of the class, field, or method. Compilers may need this information to properly compile classes that use generic types from compiled libraries. Code may access this signature by reflection.
and issue is of reflection
proguard is corrupting ie touching classes/interfaces in the Cling lib and you need to prevent that...
you could start here assuming you have a problem with Proguard touching some networking related in the Jetty/Http stack i guess from the content of your error. Wild guess is that its as if the http entity or body cant be handled as implementing the proper interfaces... You want to config proguard to avoid all interfaces in that library and you dont have any "keep interface" directives in your proguard...
For example, are you telling proguard not to touch any of the interfaces in 'org.eclipse.jetty' . You are not doing that and you might want to .
see here
scan proguard manuals for -keepinterface to use with jetty packages implementing the server/http connections in your lib.
know more about the 'cling' packages/interfaces around the internal Client-server and internal networking stack implementations in your library ( looks like it implements jetty for C-S connections on some protocol like http )
build a packages list on the lib's jar/archive to compare to your proguard config. pay special attention to interfaces being used by jetty's server implementation "jar -tf my.jar | sort | uniq" or some such
look at whats been obfuscated by proguard in 'mapping.txt' and in 'seeds.txt' explain here. intersect those packages names from those respective lists with packages & lists assembled above that you did NOT want proguard to mess with. 'seeds' should contain your jetty classes/interfaces. 'mapping' should NOT!
Maybe you could try to add -keepclassmembers in addition to -keep class for package org.fourthline.cling as this:
-keep class org.fourthline.cling.** { *;}
-keepclassmembers class org.fourthline.cling.** { *;}
In Android, I have proguard with the following settings.
-dontpreverify
# Hold onto the mapping.text file, it can be used to unobfuscate stack traces in the developer console using the retrace tool
-printmapping mapping.txt
# Keep line numbers so they appear in the stack trace of the develeper console
-keepattributes SourceFile,LineNumberTable
# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle.
-optimizations !code/simplification/arithmetic
# Activities, services and broadcast receivers are specified in the manifest file so they won't be automatically included
-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
# Custom view components might be accessed from your layout files
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# event handlers can be specified in the layout files e.g. android:onClick="nextButton_onClick", I borrowed this method name notation from .NET
-keepclassmembers class * extends android.app.Activity {
public void *_*(android.view.View);
}
# Parcelable implementations are accessed by introspection
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
# You might want to keep your annotations
-keepattributes *Annotation*
# I use Google Guava in my app
# see http://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava
-libraryjars libs/google/jsr305-1.3.9.jar;libs/pinyin4j/pinyin4j-2.5.0.jar
-dontwarn sun.misc.Unsafe
-keepclasseswithmembers class com.google.common.base.internal.Finalizer{
<methods>;
}
Some of my library, are directly imported from Java SE (Contains JApplet for example)
How I can exclude them from proguard? Note, I have pinyin4j-2.5.0.jar library in -libraryjars. I thought that's the way to tell proguard, "Hey, this is a library. Don't do anything on it, OK?" But, seems like proguard still trying to process pinyin4j-2.5.0.jar
I'm getting the following errors.
Note: there were 125 duplicate class definitions.
Warning: demo.Pinyin4jAppletDemo: can't find superclass or interface javax.swing.JApplet
Warning: demo.Pinyin4jAppletDemo$1: can't find superclass or interface java.awt.event.WindowAdapter
Warning: demo.Pinyin4jAppletDemo$2: can't find superclass or interface java.awt.event.ActionListener
Warning: demo.Pinyin4jAppletDemo$3: can't find superclass or interface java.awt.event.ActionListener
Warning: org.jasypt.encryption.pbe.PBEBigDecimalCleanablePasswordEncryptor: can't find superclass or interface org.jasypt.encryption.pbe.PBEBigDecimalEncryptor
Warning: org.jasypt.encryption.pbe.PBEBigIntegerCleanablePasswordEncryptor: can't find superclass or interface org.jasypt.encryption.pbe.PBEBigIntegerEncryptor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditorManager
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.IntrospectionException
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor
...
...
Warning: org.jasypt.normalization.Normalizer: can't find referenced class com.ibm.icu.text.Normalizer$Mode
You should check if you need to specify additional program jars.
Warning: there were 333 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Warning: there were 6 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'.
Error: Please correct the above warnings first.
Some of you may comment that for library jars which contain Java SE only methods (like Applet, Swing, ...) cannot be used in Android. Nope. In fact, they run perfectly fine, as long as you consume their non-Java SE-only methods.
The full error log can be downloaded from here : https://www.dropbox.com/s/dns62f7gp6unusg/error-log.txt
If you are sure that these Java SE classes are not used, you can indeed ignore the warnings (as you have found in your own answer). An easier way to specify this:
-dontwarn java.beans.**
-dontwarn java.awt.**
-dontwarn javax.swing.**
See ProGuard manual > Troubleshooting > Warning: can't find referenced class
Similar questions with always the same answer:
Using Proguard to Obfuscate Android App with Dropbox.com Libraries
Mobclix and Proguard
Using ProGuard with Android
Proguard tells me 'Please correct the above warnings first.
proguard hell - can't find referenced class
ProGuard with maven-android-plugin
...
Example to keep java runtime (rt.jar)
<libraryjar file="${java.home}/lib/rt.jar" />
It seems that your line
-libraryjars libs/google/jsr305-1.3.9.jar;libs/pinyin4j/pinyin4j-2.5.0.jar
is not complete.
Update
But since the needed classes do not exist on android, you have to ignore these warnings.
But do not generally ignore obfuscation warnings, we had a serious bug (using an obfuscation.map in file), because we ignored all warnings.
I merely avoid the error by
-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-dontwarn javax.swing.**
-dontwarn java.awt.**
-dontwarn org.jasypt.encryption.pbe.**
-dontwarn java.beans.**
-dontwarn org.joda.time.**
-dontwarn com.google.android.gms.**
-dontwarn org.w3c.dom.bootstrap.**
-dontwarn com.ibm.icu.text.**
-dontwarn demo.**
Here's the complete proguard configuration
-optimizationpasses 1
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#-dontobfuscate
-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-dontwarn javax.swing.**
-dontwarn java.awt.**
-dontwarn org.jasypt.encryption.pbe.**
-dontwarn java.beans.**
-dontwarn org.joda.time.**
-dontwarn com.google.android.gms.**
-dontwarn org.w3c.dom.bootstrap.**
-dontwarn com.ibm.icu.text.**
-dontwarn demo.**
# Hold onto the mapping.text file, it can be used to unobfuscate stack traces in the developer console using the retrace tool
-printmapping mapping.txt
# Keep line numbers so they appear in the stack trace of the develeper console
-keepattributes *Annotation*,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
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
# https://sourceforge.net/p/proguard/discussion/182456/thread/e4d73acf
-keep class org.codehaus.** { *; }
-assumenosideeffects class android.util.Log {
public static int d(...);
public static int i(...);
public static int e(...);
public static int v(...);
}
-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 *;
}
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
}
# I use Google Guava in my app
# see http://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava
-libraryjars libs/google/jsr305-1.3.9.jar
-keepclasseswithmembers class com.google.common.base.internal.Finalizer{
<methods>;
}
It doesn't work completely out of box yet as I still experience crash in "after proguard generated" APK.
Is pretty hard for me to find out why it crashes, as the code is obfuscate.
If I specific dontobfuscate, I will get another set of problem during generation. A message "Conversion to Dalvik format failed with error 1" pop up without additional information. But, that's another set of different problem.
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?
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..
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.
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.
signed app gives error!
my app uses an external Admob jar, however proguard is touching the jar:
the jar file is located at /libs/GoogleAdMobAdsSdk-6.2.1.jar
Thank you
LogCat error:
Proguard returned with error code 1. See console
Warning: com.google.ads.m: can't find referenced class
com.google.ads.internal.state.AdState
Warning: com.google.ads.m: can't find referenced class com.google.ads.internal.state.AdState
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
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)
which is inside the jar-file
Config proguard-project.txt:
-libraryjars /libs/GoogleAdMobAdsSdk-6.2.1.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-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.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-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.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
after adding
-keep public class com.google.ads.**
to the file, the eclipse console gives still the following error:
Proguard returned with error code 1. See console
Note: there were 160 duplicate class definitions.
Warning: com.google.ads.m: can't find referenced class
com.google.ads.internal.state.AdState
Warning: com.google.ads.m: can't find referenced class
com.google.ads.internal.state.AdState
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
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)
I just added the
-dontwarn com.google.ads.**
to the proguard-project.txt file and the signed apk works fine!
this is recommended (like Eric said before) here: Proguard can't find referenced class com.google.ads.internal.state.AdState
This worked for me on It seems that you need to add these 2 items to the proguard config :
-dontwarn com.google.ads.**
-keep class com.google.ads.** {*;}
-dontwarn com.google.ads.**
here secure the ads class
if you want to secure your class then add com.pkgname.**
I get an exception when I istall my app on the phone. It works without proguard. What is wrong in my configuration? Thank you very much! The config is a default android config i found somwhere. Dont know whats going on
D/AndroidRuntime(15388): Shutting down VM
W/dalvikvm(15388): threadid=1: thread exiting with uncaught exception (group=0x40c3a1f8)
E/AndroidRuntime(15388): FATAL EXCEPTION: main
E/AndroidRuntime(15388): java.lang.NullPointerException
E/AndroidRuntime(15388): at aV.setViewValue(SourceFile:163)
E/AndroidRuntime(15388): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:168)
E/AndroidRuntime(15388): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
E/AndroidRuntime(15388): at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
E/AndroidRuntime(15388): at android.widget.AbsListView.obtainView(AbsListView.java:2214)
E/AndroidRuntime(15388): at android.widget.ListView.makeAndAddView(ListView.java:1774)
E/AndroidRuntime(15388): at android.widget.ListView.fillDown(ListView.java:672)
E/AndroidRuntime(15388): at android.widget.ListView.fillFromTop(ListView.java:732)
E/AndroidRuntime(15388): at android.widget.ListView.layoutChildren(ListView.java:1625)
E/AndroidRuntime(15388): at android.widget.AbsListView.onLayout(AbsListView.java:2044)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
E/AndroidRuntime(15388): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
E/AndroidRuntime(15388): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1628)
E/AndroidRuntime(15388): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2585)
E/AndroidRuntime(15388): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15388): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(15388): at android.app.ActivityThread.main(ActivityThread.java:4507)
E/AndroidRuntime(15388): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(15388): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(15388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
E/AndroidRuntime(15388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/AndroidRuntime(15388): at dalvik.system.NativeStart.main(Native Method)
here is my proguard config
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars /libs/android-support-v13.jar
#
# This ProGuard configuration file illustrates how to process Android
# applications.
# Usage:
# java -jar proguard.jar #android.pro
#
# If you're using the Android SDK (version 2.3 or higher), the android tool
# already creates a file like this in your project, called proguard.cfg.
# It should contain the settings of this file, minus the input and output paths
# (-injars, -outjars, -libraryjars, -printmapping, and -printseeds).
# The generated Ant build file automatically sets these paths.
# Specify the input jars, output jars, and library jars.
# Note that ProGuard works with Java bytecode (.class),
# before the dex compiler converts it into Dalvik code (.dex).
# Save the obfuscation mapping to a file, so you can de-obfuscate any stack
# traces later on.
-printmapping bin/classes-processed.map
# You can print out the seeds that are matching the keep options below.
#-printseeds bin/classes-processed.seeds
# Preverification is irrelevant for the dex compiler and the Dalvik VM.
-dontpreverify
# Reduce the size of the output some more.
-repackageclasses ''
-allowaccessmodification
# Switch off some optimizations that trip older versions of the Dalvik VM.
-optimizations !code/simplification/arithmetic
# Keep a fixed source file attribute and all line number tables to get line
# numbers in the stack traces.
# You can comment this out if you're not interested in stack traces.
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# RemoteViews might need annotations.
-keepattributes *Annotation*
# Preserve all fundamental application classes.
-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
# Preserve all View implementations, their special context constructors, and
# their setters.
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# Preserve all classes that have special context constructors, and the
# constructors themselves.
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
# Preserve all classes that have special context constructors, and the
# constructors themselves.
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# Preserve the special fields of all Parcelable implementations.
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve the required interface from the License Verification Library
# (but don't nag the developer if the library is not used at all).
#-keep public interface com.android.vending.licensing.ILicensingService
#-dontnote com.android.vending.licensing.ILicensingService
# The Android Compatibility library references some classes that may not be
# present in all versions of the API, but we know that's ok.
-dontwarn android.support.**
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
# Preserve the special static methods that are required in all enumeration
# classes.
-keepclassmembers class * extends java.lang.Enum {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
# You can comment this out if your application doesn't use serialization.
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual.
#-keepclassmembers class * implements java.io.Serializable {
# static final long serialVersionUID;
# static final java.io.ObjectStreamField[] serialPersistentFields;
# private void writeObject(java.io.ObjectOutputStream);
# private void readObject(java.io.ObjectInputStream);
# java.lang.Object writeReplace();
# java.lang.Object readResolve();
#}
# Your application may contain more items that need to be preserved;
# typically classes that are dynamically created using Class.forName:
# -keep public class mypackage.MyClass
# -keep public interface mypackage.MyInterface
# -keep public class * implements mypackage.MyInterface
# Needed by google-api-client to keep generic types and #Key annotations accessed via reflection
-keepclassmembers class * {
#com.google.api.client.util.Key <fields>;
}
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault,*Annotation*
-dontwarn sun.misc.Unsafe
-keepattributes
-dontoptimize
#-dontshrink
Setting the Scene
I currently have the exact same problem. I have perfectly working code with a custom adapter with layout inflater using the format with parent and false as 2nd and 3rd argument.
Since the code runs fine without obfuscation I feel confident enough to ignore all the questions and responses on stackoverflow about null views being returned due to wrong use of the Android API.
If you also have the issue without obfuscation ignore this answer and question and move on! Check these questions
I'll do my best to report my findings in this answer. This answer might grow over time. Skip to Conclusion at the bottom if you're eager to know the latest.
The Quick and Dirty Solution
Straight forward solution here is to update your proguard configuration to exclude the class your code fails on after obfuscation.
That should look something like this in your proguard config file:
-keep class * extends your.company.secret.package
For more information on proguard start looking here. Also make sure you have at least the minimal required proguard config file for an Android project. Check this example.
Mapping Back to your Source Code
When looking into this you might be interested in what the original name of that class was before obfuscation. That should make it a lot easier. You can find this mapping in the bin folder of your project in a proguard folder in the mapping.txt file.
/bin/proguard/mapping.txt
Pinned Down to the following lines of code
In my case I was able to pin down the error on the following lines of codes. These lines were only present in the adapter that failed while other code was common with the working adapters. All of below code is part of the getView(final int position, View convertView, final ViewGroup parent):View method
holder.layout.removeAllViews();
TextView tView;
for (final String text : mItems.getTextList()) {
tView = new TextView(mContext);
tView.setTextSize(14);
tView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tView.setText(text);
holder.layout.addView(tView);
}
If I just remove the addView() and removeAllViews() calls than all goes well.
Android Source Code
My first idea was to check the source code for that line of code. I found the following point in the stacktrace.
11-20 14:19:40.709: E/AndroidRuntime(22236): FATAL EXCEPTION: main
11-20 14:19:40.709: E/AndroidRuntime(22236): Process: your.company.secret.package, PID: 22236
11-20 14:19:40.709: E/AndroidRuntime(22236): java.lang.NullPointerException
11-20 14:19:40.709: E/AndroidRuntime(22236): at android.widget.AbsListView.obtainView(AbsListView.java:2265)
The Source for AbsListView can be found on grepcode.However looking at that code didn't give me a lot of courage of finding a solution there. Instead I turned to other resources. Might come back to this later.
I executed this code on an Android 4.4 device so the line number didn't even match.
tested on a 4.3 device
Correct line of code is 2177. Matches with this line:
child = mAdapter.getView(position, null, this);
Sample Project
See https://github.com/hanscappelle/so-10822397 for a sample project. You'll need Android Studio (Beta) 0.8.2 and latest build tools. I also had to manually fetch the proguard-android.txt file and put it in place.
You can comment out the lines in the adapter that work on the layout field of the static ViewHolder class. Those are the ones that fail once proguard is enabled and the app runs on a device.
Things I plan to do next
(DONE) I have other adapters in code that work fine even after obfuscation. I'll check these for differences with the once that fail
(DONE) I really have to check for a 4.3 device so I can look into Android Source code properly.
(DONE) Create sample project
TODO complete analysis with sample project
Conclusion
Seems to be related to dynamically adding views in the getView() method of the custom adapter. That in combination with code obfuscation.
Try turning off more optimizations that might be blowing up Dalvik. Upon further inspection it looks like you're disabling all optimizations actually.
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
Also try preserving these..
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
EDIT: Here is my proguard file, wonder if just replacing it will work. Its the default file generated by by ADT so nothing special here.
-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
-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 *;
}