Rare Android Unable to Instantiate Application Exception - android

I'm seeing the following exception under Crashes in the dev console from time to time.
Whats puzzling about it is that google maps shows up in the call stack as if its calling or creating my app class - very confusing. Whats further weird is the "MyApp-2.apk" in the call stack - where it appends the "-2".
I do include the android.maps.jar file in the libs.
I would like to know how to recreate this if possible and how to prevent this from happening?
java.lang.RuntimeException: Unable to instantiate application com.MyApp.MyCustomApp:
java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp"
on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at android.app.LoadedApk.makeApplication(LoadedApk.java:503)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4405)
at android.app.ActivityThread.access$1400(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5059)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp" on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:967)
at android.app.LoadedApk.makeApplication(LoadedApk.java:498)
... 11 more
Manifest Application Tag:
<application
android:name=".MyApp"
android:hardwareAccelerated="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
I'm using these JARS: android-support-v4-r2-googlemaps.jar + android-support-v4.jar

The prime reason why a Class within your application would be present on your test devices but missing at runtime on some others would be if your class has a dependency on some external feature which is missing on those devices. For example, if you used some Google API which is not part of AOSP and so missing on a plain AOSP build, or a vendor build which does not license these, then your class will be pruned at install time as its dependencies cannot be resolved.
A common reason for your app finding its way into such circumstances might be someone running an inconsistently assembled "custom ROM" on their device.

Related

Android ZBar Exception only with Jenkins build

I have an android project with a QR scan activity. I use the ZBar library for this: http://sourceforge.net/projects/zbar/files/AndroidSDK/
If the project is built on a PC or Mac with exlipse, the app works fine.
If it's build by jenkins (same source from git) the app crashes.
The Exception I get is:
at controller.gui.activity.QRScanActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchFieldError: no field with name='peer' signature='J' in class Lnet/sourceforge/zbar/ImageScanner;
at net.sourceforge.zbar.ImageScanner.init(Native Method)
at net.sourceforge.zbar.ImageScanner.<clinit>(Unknown Source)
... 16 more
I used the demo app for a base.
Is this a Jenkins config problem?
The Zbar library is not just a jar file, it's a C library with jni. So I have a jar file and 3 folders (for different architectures I think) and they have a libiconv.so and a libzbarjni.so files.
Add -keep class net.sourceforge.zbar.** { *; } to your proguard config file
I Dont know if you already figured it out, but this is a proguard issue. Seems your JNI classes are not being obfuscated correctly. You might need to change your proguard config to skip ZBar files.

What could be causing a ClassNotFoundException?

So I've been working on an app lately which runs fine on most devices. However, sometimes the app crashes at start up with the following error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.mypackage.app/com.mypackage.app.activities.MainPager}:
java.lang.ClassNotFoundException: com.mypackage.app.activities.MainPager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
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:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException:
com.mypackage.app.activities.MainPager
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1986)
... 12 more
I get that this is because it can't find the class called MainPager. But how is that even possible? I mean, the class should be there.. I put it there myself :) . Why on earth is it not finding it?
EDIT: I think the cause may be that in my manifest I have android:package="com.mypackage.app" defined, but that my launch activity is in the package com.mypackage.app.activities. Currently testing this theory. Still weird that it only happens on some devices, though.
This solution won't work, since I then can't update the APK in Google Play (has to be the same package name in the manifest).
Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...
in the manifest you add Activity name like this
android:name=".activities.MainPager"
because you have given package name
android:package="com.mypackage.app"
Now I am using ART runtime on Nexus 5, and I am getting ClassNotFound for some apps.
You can safely ignore those if that's the case for your users.

java.lang.NoClassDefFoundError on an Activity

I receive a crash report from my production app, which tells me that there is an NoClassDefFound Exception on one of my activity.
The exception is thrown on this line:
final Intent i = new Intent(MainActivity.this, SomeActivity.class);
Where it claims that "SomeActivity" class is not found.
There is only one instance reported out of thousands of users. (On a Samsung Note Mini)
Which means it shouldn't be a compilation or wrong lib included issue.
Is there any clues for me to continue my investigation?
p/s: The activity is definitely defined in manifest. Else it won't even works on other user's phones.
Stack:
java.lang.NoClassDefFoundError: com.sensored.SomeActivity
at com.sensored.MainActivity$2.onItemClicked(MainActivity.java:920)
at com.sensored.adapter.SomeListAdapter$2.onClick(SomeListAdapter.java:115)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3697)
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:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
1) Keep all activities under same package[say com.compname.proj.views].
2) Ensure in manifest, package attribute is set to the above package[i.e com.compname.proj.views].
3) In manifest, under all activity tag, make sure android:name attribute has values matching to below pattern:
android:name=".<your activity class name>"
Ex: android:name=".SomeActivity"
My point is not to use package name + activity class name for manifest activity declaration.

NoClassDefFoundError occured while initiate fragment

java.lang.NoClassDefFoundError occured at the first line:
FirstFragment firstTab = FirstFragment.newInstance(10);
mTabsAdapter.addTab(generateTabSpec(0, mTabHost),
firstTab.getClass(), null);
But I'm pretty sure the Fragment exist! (it's a fragment so don't need to check if declared in Manifest.) Even refactoring its name or move to other package didn't fix the problem. Here's the stacktrace:
ERROR/AndroidRuntime(23608): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: dev.twothree.android.wtf.FirstFragment
at dev.twothree.android.activity.FragmentTab.setupTabHost(FragmentTab.java:110)
at dev.twothree.android.activity.FragmentTab.onCreate(FragmentTab.java:75)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2207)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
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:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Is it a bug of Intell J 12.0.4? My version is Build #IC-123.169. Later I'll try it in the Eclipse, but still hope it can be resolved in Intelli J.
After open the whole project with Eclipse, config all the dependencies ONCE AGAIN, Eclipse point out that I accidentally CAST one of the custom library class to another class. Maybe that's why no successful compiled class file existed for later invoke.
Anyway, it seems Intelli-J didn't found that error while 3rd party library is involved, it could be a bug. But the blame is also on me for not find that so obvious error.

Application class not found in Android after using ProGuard

My application worked well, without any errors, so far. But lately I've began using ProGuard to obfuscate the code now I see the following error report in the Google Play developer console:
java.lang.RuntimeException: Unable to instantiate application MYPACKAGE.MyApp: java.lang.ClassNotFoundException: MYPACKAGE.MyApp
at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3950)
at android.app.ActivityThread.access$1300(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: MYPACKAGE.MyApp
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:945)
at android.app.LoadedApk.makeApplication(LoadedApk.java:477)
MyApp is the custom application class, obviously. There's only one error report on that issue so far, although there are 10,000+ active installations. Does that mean I shouldn't bother with that problem or could it be a serious issue? How can I resolve this?
try add this lines:
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
to proguard.cfg file
ProGuard simply replaces class names by obfuscated class names. If the processed code works on one device (or 10,000+ devices), it should work on all devices.
Moreover, if you disassemble the processed application, you'll see that mypackage.MyApp is still there, with its original name. The default integration of ProGuard in the Android build takes care of keeping activities, services, etc, without any need for additional -keep options.
In short, this is some sort of fluke, most probably unrelated to obfuscation. Simply reinstalling the application may help.
Seems like your class names are missing in proguard's obfuscation configuration. Add the following to your proguard.cfg with the missing class names.
-keep public class your_missing_class_full_name

Categories

Resources