I'm using the newest ActionBarSherlock release (4.4) and many of my Android 2 users experience a fatal crash while the sherlock library tries to load the activity icon.
I tried cleaning the project but the bug keeps appearing (I suspect the generated R file for the library is incorrect?). I found some topics covering this crash but no working solutions.
My project exists out of the ActionBarSherlock library which is used by another library project containing some Activities. A few other Android projects use the library project with the Activities in it. I don't think this could be the problem, could it?
Important thing to notice is that the app works fine on a emulator running Android 2.x. I'm also using proguard.
Could the crash have something to do with the loadLogoFromManifest method?
https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock/src/com/actionbarsherlock/internal/ResourcesCompat.java#L112
Devices and Android versions affected so far
Optimus L3 (e0)
Galaxy Pocket (GT-S5300)
Galaxy Y (GT-S5360)
Android 2.3.3 - 2.3.7
Proguard
-keepattributes SourceFile,LineNumberTable
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*
-keep public class * extends com.actionbarsherlock.app.SherlockListFragment
-keep public class * extends com.actionbarsherlock.app.SherlockFragment
-keep public class * extends com.actionbarsherlock.app.SherlockDialogFragment
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
Stacktrace
java.lang.RuntimeException: Unable to start activity ComponentInfo{packagehere/activityhere}: android.view.InflateException: Binary XML file line #32: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1010)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:902)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:836)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:261)
at someactivity.onCreate(BibleMain.java:128)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 24 more
Caused by: android.content.res.Resources$NotFoundException: File from drawable resource ID #0x7f020091
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.Resources.getDrawable(Resources.java:581)
at com.actionbarsherlock.internal.widget.ActionBarView.(ActionBarView.java:191)
... 27 more
Caused by: java.io.FileNotFoundException:
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:406)
at android.content.res.Resources.loadDrawable(Resources.java:1706)
... 29 more
Related
I am using android-support-library-v7 in my project and of course I would like to use progurad to minimize and obfuscate my code.
The problem is that if I use proguard I get errors similar to this:
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.project/org.example.project.ActivityMain}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.preference.PreferenceCategory
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.preference.PreferenceCategory
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.h.a(Unknown Source)
at android.support.v7.preference.h.b(Unknown Source)
at org.exampple.project.ActivityMain.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
... 11 more Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getConstructor(Class.java:431)
... 22 more
PreferenceCategory is used in my preferences.xml file and I guess it is accessed via reflection. Proguard if probably removes this method (or class) if it is not referenced in code when shrinking. And even if not it surely obfuscates the name.
Google in itßs usual fashion provides absolutely no documentation on the subject.
So, what are the optimum settings to achieve good shrinking and good obfuscation.
There are some similar questions on Stack Overflow, but they boil down to:
-keep class android.support.v7.** { *; }
which cleary defeats the purpose of shrinking and obfuscating.
Trying to randomly guess the settings or by try and error method is extremely time consuming.
The Support Library uses the consumerProguardFiles feature to automatically include the appropriate ProGuard if you're using Gradle, meaning you don't need to manually include anything.
Looking at the ProGuard file for preferences-v7 (stored in the proguard.txt file within the AAR), it contains the following lines:
# Preference objects are inflated via reflection
-keep public class android.support.v7.preference.Preference {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keep public class * extends android.support.v7.preference.Preference {
public <init>(android.content.Context, android.util.AttributeSet);
}
Which covers the exact method that it says you are missing (as PreferenceCategory indirectly extends Preference). Check to make sure you are using the full Gradle dependency.
Check out this project on Github that has proguard rules for popular libraries.
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.** { *; }
Since I updated Android Studio to version 1.2.1.1 I have the following problem:
Whenever I build a release version / build variant of my app, I get a NoClassDefFoundError on the Adjust library I have included in the project as a library module.
The stracktrace:
java.lang.NoClassDefFoundError: com.adjust.sdk.AdjustConfig
at de.myapp.GlobalApp.prepareAdjust(GlobalApp.java:111)
at de.myapp.GlobalApp.onCreate(GlobalApp.java:71)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:999)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4151)
at android.app.ActivityThread.access$1300(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Corresponding part of my code:
AdjustConfig config = new AdjustConfig(this, someString, otherString);
When I turn off Proguard with minifyEnabled false; in my build.gradle, the error is gone.
My proguard-rules.pro looks like this:
-keepattributes **
-keep class !android.support.v7.internal.view.menu.**,** {*;}
-dontpreverify
-dontoptimize
-dontshrink
-dontwarn **
These Proguard rules might look a bit strange because they do but one thing: obfuscate classes in the android.support.v7.internal.view.menu package.
This procedure is a workaround for a a known issue of the Android Support library on Samsung devices.
Even more confusingly, the NoClassDefFoundError only occurs only devices running Android < 5.0.
Any ideas on what the reason could be or how to fix this?
The documentation says:
If you are using Proguard, add these lines to your Proguard file:
-keep class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.** { *; }
-keep class com.google.android.gms.ads.identifier.** { *; }
I am getting this exception. Please find below the complete stack trace.
com.facebook.FacebookGraphObjectException: Factory can't proxy method: public abstract java.lang.String com.junobe.android.junowallet.SNS.u.a()
at com.facebook.model.GraphObject$Factory.verifyCanProxyClass(SourceFile:290)
at com.facebook.model.GraphObject$Factory.createGraphObjectProxy(SourceFile:216)
at com.facebook.model.GraphObject$Factory.access$0(SourceFile:215)
at com.facebook.model.GraphObject$Factory$GraphObjectProxy.proxyGraphObjectMethods(SourceFile:583)
at com.facebook.model.GraphObject$Factory$GraphObjectProxy.invoke(SourceFile:521)
at $Proxy0.cast()
at com.facebook.Response.getGraphObjectAs(SourceFile:124)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController.handleResponse(SourceFile:568)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController.access$6(SourceFile:555)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController$3.onPostExecute(SourceFile:522)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController$3.onPostExecute(SourceFile:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3685)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(NativeStart.java)
I am not getting this issue on all devices or all times. Identified this from crashlytics.
I have a hunch that it may be some proguard - obfuscation issue on Android.
I have added the following lines to in the proguard file (As per facebook Documentation):
-keep class com.facebook.** { *; }
-keepattributes Signature
Is there something I am missing .. Any assistance or solution would be welcome.
The only thing that I found that worked for me was to not obfuscate classes that extended facebook classes. I had a bunch of files in one package so for all those files I just excluded them by adding this to my proguard-project.txt.
-keep class com.classes.extending.facebook.** { *; }
I just developed my application and want to release but before that i want to remove the logs and other unnecessary things. The best way i find that to use Proguard. I am using command line so i use the command ant release and my application is built successfully and the new apk file which is generated in /bin directory is <app-name>-release.apk. I installed that apk in my device but after few screens its crashed and when i tried with restating my application and moved to other tabs then its crashed at some points.
Don't know why its happened. so this is the contain of my project.properties file
target=android-15
proguard.config=proguard-project.txt
And this is my proguard-project.txt
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars smack.jar
-libraryjars libphonenumber-5.0v1.5.jar
#-keep class com.** { *; }
#-keep class org.** { *; }
-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>;
}
-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 *;
}
Error Log:
10-08 07:25:18.356: E/AndroidRuntime(1733): FATAL EXCEPTION: Contact_sync_Service
10-08 07:25:18.356: E/AndroidRuntime(1733): java.lang.NoClassDefFoundError: com.google.i18n.phonenumbers.PhoneNumberUtil
10-08 07:25:18.356: E/AndroidRuntime(1733): at org.sipchat.sipua.ui.ai.run(Unknown
Source)
10-08 07:25:18.356: E/AndroidRuntime(1733): at java.lang.Thread.run(Thread.java:856)
10-08 07:26:26.756: E/dalvikvm(1751): Could not find class 'org.jivesoftware.smack.filter.MessageTypeFilter', referenced from method org.sipchat.sipua.ui.ConnectionService.a
10-08 07:26:26.786: E/dalvikvm(1751): Could not find class 'org.jivesoftware.smack.ConnectionConfiguration', referenced from method org.sipchat.sipua.ui.ConnectionService.onStartCommand
10-08 07:26:26.806: E/dalvikvm(1751): Could not find class 'org.jivesoftware.smack.ConnectionConfiguration', referenced from method org.sipchat.sipua.ui.af.run
10-08 07:26:26.956: E/AndroidRuntime(1751): FATAL EXCEPTION: main
10-08 07:26:26.956: E/AndroidRuntime(1751): java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration
10-08 07:26:26.956: E/AndroidRuntime(1751): at org.sipchat.sipua.ui.ConnectionService.onStartCommand(Unknown Source)
10-08 07:26:26.956: E/AndroidRuntime(1751): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
10-08 07:26:26.956: E/AndroidRuntime(1751): at android.app.ActivityThread.access$1900(ActivityThread.java:123)
10-08 07:26:26.956: E/AndroidRuntime(1751): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
10-08 07:26:26.956: E/AndroidRuntime(1751): at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 07:26:26.956: E/AndroidRuntime(1751): at android.os.Looper.loop(Looper.java:137)
10-08 07:26:26.956: E/AndroidRuntime(1751): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-08 07:26:26.956: E/AndroidRuntime(1751): at java.lang.reflect.Method.invokeNative(Native Method)
10-08 07:26:26.956: E/AndroidRuntime(1751): at java.lang.reflect.Method.invoke(Method.java:511)
10-08 07:26:26.956: E/AndroidRuntime(1751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-08 07:26:26.956: E/AndroidRuntime(1751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-08 07:26:26.956: E/AndroidRuntime(1751): at dalvik.system.NativeStart.main(Native Method)
Update :
The packages which are mentioned in error are the packages of jar files which i added already in proguard-project.txt
Please make me clear if i went wrong anywhere?Thanks
Did you gave Dexguard a try? As it says on the proguard website
ProGuard now has a sibling optimizer and obfuscator for Android:
DexGuard. It is compatible with ProGuard, and it provides additional
features like string encryption, class encryption, and hiding access
to sensitive APIs. It directly targets Dalvik bytecode and streamlines
the Android build process.
http://www.saikoa.com/dexguard