android java.lang.AssertionError: java.lang.NoSuchMethodException - Proguard - android

I am getting my app crashed with this error, in the released version of app.
Its working fine in debug mode
Process: com.app, PID: 13162
java.lang.AssertionError: java.lang.NoSuchMethodException: <init> [interface twitter4j.conf.Configuration, interface twitter4j.a.b]
at twitter4j.n.<clinit>(Unknown Source)
at com.app.activities.RegistrationActivity.g(Unknown Source)
at com.app.activities.RegistrationActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NoSuchMethodException: <init> [interface twitter4j.conf.Configuration, interface twitter4j.a.b]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getDeclaredConstructor(Class.java:510)
at twitter4j.n.<clinit>(Unknown Source)
at com.app.activities.RegistrationActivity.g(Unknown Source)
at com.app.activities.RegistrationActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
The error seems to be generated because of proguard file
Here is the proguard-rules.pro as follows -
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/adisoft2/android/android-sdk-linux/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
#-injars bin/classes
#-injars libs
#-outjars bin/classes-processed.jar
#-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar
-keep class twitter4j.conf.**
-keep class twitter4j.TwitterImpl
-keep class twitter4j.conf.PropertyConfigurationFactory
-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
#retrofit.http.* <methods>;
}
-dontwarn twitter4j.**
-dontwarn com.google.android.gms.**
-dontwarn okio.**
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
Please let me know, what am I doing wrong, and how to fix.

Adding this in proguard-rules.pro worked for me.
-keep class twitter4j.** { *; }

Yes I accept the above (NarendraJi) answer. But in my case, it was not showing which library or class creating the issue.
It is showing like
Caused by: java.lang.NoSuchMethodException: <init>
at com.a.f
From the above information we cannot understand the problem. So I used the "app/build/outputs/release/mapping.txt" file.
mapping.txt file having clear information about all classes,methods and packages. So we can easily solve this type of problems

Related

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/ldap/LdapName

I have implemented ProGuard to cut off unnecessary codes. But after the app starts, I am getting the following error -
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/ldap/LdapName;
at b.a.b.e.d.a.b(Unknown Source)
at b.a.b.e.d.a.a(Unknown Source)
at b.a.b.e.d.a.a(Unknown Source)
at b.a.b.e.d.a.a(Unknown Source)
at b.a.b.e.d.f.a(Unknown Source)
at b.a.b.e.d.f.a(Unknown Source)
at b.a.b.e.d.f.a(Unknown Source)
at b.a.b.h.c.h.a(Unknown Source)
at b.a.b.h.c.p.a(Unknown Source)
at b.a.b.h.b.o.a(Unknown Source)
at b.a.b.h.b.o.a(Unknown Source)
at b.a.b.h.b.a.a(Unknown Source)
at b.a.b.h.b.h.a(Unknown Source)
at b.a.b.h.b.h.a(Unknown Source)
at b.a.b.h.b.h.execute(Unknown Source)
at com.c.a.ae.a(Unknown Source)
at com.c.a.b.a(Unknown Source)
at com.c.a.aa.run(Unknown Source)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.ldap.LdapName" on path: DexPathList[[zip file "/data/app/bd.com.chalo-1/base.apk"],nativeLibraryDirectories=[/data/app/bd.com.chalo-1/lib/arm64, /data/app/bd.com.chalo-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 19 more
Suppressed: java.lang.ClassNotFoundException: javax.naming.ldap.LdapName
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 20 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
What should I do now? Does it something to do with my library?
Android’s documentation for ProGuard describes it like so:
“The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer…. Having ProGuard run is completely optional, but highly recommended.”
Now adding proguard can cause problems if your app contain third party libraries, broadcast receivers, custom widgets etc.. so you need to add proguard rules to add this classes in runtime otherwise the classes will not compile in APK version and you will get errors
For details about proguard and it's usage see this link:http://omgitsmgp.com/2013/09/09/a-conservative-guide-to-proguard-for-android/
there is a standard proguard rules form which you can use:
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Obfuscation parameters:
#-dontobfuscate
-useuniqueclassmembernames
-keepattributes SourceFile,LineNumberTable
-allowaccessmodification
# Ignore warnings:
#-dontwarn org.mockito.**
#-dontwarn org.junit.**
#-dontwarn com.robotium.**
#-dontwarn org.joda.convert.**
# Ignore warnings: We are not using DOM model
-dontwarn com.fasterxml.jackson.databind.ext.DOMSerializer
# Ignore warnings: https://github.com/square/okhttp/wiki/FAQs
-dontwarn com.squareup.okhttp.internal.huc.**
# Ignore warnings: https://github.com/square/okio/issues/60
-dontwarn okio.**
# Ignore warnings: https://github.com/square/retrofit/issues/435
-dontwarn com.google.appengine.api.urlfetch.**
# Keep the pojos used by GSON or Jackson
-keep class com.futurice.project.models.pojo.* { ; }
# Keep GSON stuff
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.* { ; }
-keep public class Socket
# Keep Jackson stuff
-keep class org.codehaus.* { ; }
-keep class com.fasterxml.jackson.annotation.* { ; }
# Keep these for GSON and Jackson
-keepattributes Signature
-keepattributes Annotation
-keepattributes EnclosingMethod
# Keep Retrofit
-keep class retrofit.* { ; }
-keepclasseswithmembers class * {
#retrofit.** *;
}
-keepclassmembers class * {
#retrofit.** *;
}
-keep public class com.mikhaellopez:circularimageview:2.1.1.* { ; }
# Keep Picasso
-keep class com.squareup.picasso.* { ; }
-keepclasseswithmembers class * {
#com.squareup.picasso.** *;
}
-keepclassmembers class * {
#com.squareup.picasso.** *;
}
add this rules in your proguard files ...
For details of the standard form see this:https://github.com/futurice/android-best-practices/blob/master/templates/rx-architecture/app/proguard-rules.pro
and this:
https://gist.github.com/Jackgris/c4a71328b1ae346cba04

Android - Signed apk not run in mobile device

I am facing very strange problem. When I directly copy APK from bin folder of project and paste in mobile phone SD card. And install it, it working fine. While I do same with export signed APK from Android Tool in project and placed APK in SD card. It install successfully but not run. I do not know why this is happen. I also you progaurad in app. Is it cause of crashing app??
Here is logcat output
> FATAL EXCEPTION: main
Process: com.globalassignmenthelp, PID: 7708
java.lang.AbstractMethodError: abstract method "android.view.View q.a(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet)"
at r.onCreateView(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreateView(Unknown Source)
at com.globalassignmenthelp.Perspective.onCreateView(Unknown Source)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3571)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3644)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381)
at android.app.Activity.setContentView(Activity.java:2159)
at com.globalassignmenthelp.Perspective.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5966)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2517)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Please help and Thanks in Advance.
I think you are using wrong proguard. This type of problem comes when something wrong with progurad. Try to replace your project.properties with this code-
here is link - Progurad Code
Hope this will help you.
add this code to proguard.txt
if you are using v4
# support-v4
-dontwarn android.support.v4.**
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v4.** { *; }
if you are using v7
# support-v7
-dontwarn android.support.v7.**
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }

Android Cling/Upnp proguard

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.** { *;}

Exclude Java SE library from Android proguard

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.

When using Proguard, do you need a separate config for each referenced library?

My application has references to HoloEverywhere and SherlockActionBar, both which are in-workspace projects. When I enabled Proguard for the application only, it crashes giving these errors:
11-15 11:50:11.090: E/AndroidRuntime(24823): Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.app.Activity, int]
11-15 11:50:11.090: E/AndroidRuntime(24823): at com.actionbarsherlock.a.a(Unknown Source)
11-15 11:50:11.090: E/AndroidRuntime(24823): at org.holoeverywhere.a.a.l(Unknown Source)
11-15 11:50:11.090: E/AndroidRuntime(24823): at org.holoeverywhere.a.a.setContentView(Unknown Source)
Is this because I only enabled Proguard for the app and not the other in-workspace projects HE and ABS?
I am using the default proguard-project.txt in the sdk and did not add any additional rules.
No you do not.
Use these rules to keep the referenced classes un-obfuscated.
-keep class com.actionbarsherlock.** {*;}
-keep class org.holoeverywhere.** {*;}
this also will help
## ActionBarSherlock 4.4.0 specific rules ##
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*
## hack for Actionbarsherlock 4.4.0, see https://github.com/JakeWharton/ActionBarSherlock/issues/1001 ##
-dontwarn com.actionbarsherlock.internal.**

Categories

Resources