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.** { *; }
Related
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
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
On enabling proguard, I am getting the following warning
**Warning:com.mixpanel.android.mpmetrics.Tweaks: can't find referenced class com.mixpanel.android.mpmetrics.Tweaks$TweakType
Warning:there were 1 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
:app:proguardStageRelease FAILED
Error:Execution failed for task ':app:proguardStageRelease'.
java.io.IOException: Please correct the above warnings first.**
logcat on putting -dontwarn com.mixpanel.**
java.lang.NullPointerException
at com.leadsquared.app.LeadsActivity.onCreateOptionsMenu(Unknown Source)
at android.app.Activity.onCreatePanelMenu(Activity.java:2546)
at android.support.v4.app.o.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.view.k.onCreatePanelMenu(Unknown Source)
at android.support.v7.app.aj.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.view.k.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.a.b.g(Unknown Source)
at android.support.v7.internal.a.c.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
proguard-rules.pro file is like this
-dontshrink
-dontoptimize
-dontpreverify
-dontwarn okio.**
-dontwarn com.mixpanel.**
-keep class com.squareup.okhttp.** { *; }
-dontwarn org.xmlpull.v1.**
-dontwarn com.squareup.**
-keep interface com.squareup.okhttp.** { *; }
-keepclasseswithmembers class * {
void onClick*(...);
}
-keepclasseswithmembers class * {
*** *Callback(...);
}
Any help is appreciated
Add this to your proguard config:
-dontwarn com.mixpanel.**
see also here
The problem:
I'm using android mobile services, which relies on androidhttpclient.
Referencing org.apache.http.legacy resolves all the problems and the app runs just fine. However, with proguard on, I keep running into issues.
The problem plays out in two scenarios. If I keep the export checkbox checked (in jave build path), I get a 'Stub!' exception as expected (see discussion below)(see screenshot for which checkbox I'm talking about)
The runtime crash of type: "Stub!":
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stuffd/com.stuffd.MainActivity}: java.lang.RuntimeException: Stub!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.RuntimeException: Stub!
at org.apache.http.message.AbstractHttpMessage.(AbstractHttpMessage.java:7)
at org.apache.http.client.methods.HttpRequestBase.(HttpRequestBase.java:7)
at org.apache.http.client.methods.HttpGet.(HttpGet.java:8)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.executeGetRecords(MobileServiceJsonTable.java:952)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.executeUrlQuery(MobileServiceJsonTable.java:183)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.execute(MobileServiceJsonTable.java:160)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceTable.execute(MobileServiceTable.java:158)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceTable.execute(MobileServiceTable.java:249)
at com.microsoft.windowsazure.mobileservices.table.query.ExecutableQuery.execute(ExecutableQuery.java:101)
If however, I keep the checkbox unchecked (as suggested - see discussion below), I get and AbstractMethodError exception.
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.AbstractMethodError: abstract method "java.lang.String org.apache.http.client.methods.HttpRequestBase.getMethod()"
at android.net.http.AndroidHttpClient.getMethod(AndroidHttpClient.java:283)
at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:301)
proguard config used:
-dontwarn org.apache.http.**
-dontwarn android.net.http.**
-dontwarn com.microsoft.windowsazure.mobileservices.**
Has anyone else run into this and has figured it out?
Here's what I am using, allowing the OS to properly replace the stubbed methods at runtime.
-keep class org.apache.http.** { *; }
-keep class org.apache.commons.codec.** { *; }
-keep class org.apache.commons.logging.** { *; }
-keep class android.net.compatibility.** { *; }
-keep class android.net.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.webkit.**
It's all the stubbed packages provided by org.apache.http.legacy.jar.
You're right not exporting the legacy apache lib. However it has to be located outside the libs folder and added to the Build Path (when using Eclipse). Otherwise it gets exported anyway with your Android Private Libraries.
I'm using GMS, Volley and AndroidHttpClient in my own communication classes.
Here's what I had to add to the proguard settings:
-dontwarn org.apache.http.**
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
-dontwarn com.myapp.communication.**
-keep class com.google.android.gms.** { *; }
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.**