I have some problems with my Native Activity application. It works fine on 99% of devices. But sometimes users get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{nightradio.sunvox/nightradio.sunvox.MyNativeActivity}:
java.lang.IllegalArgumentException: Unable to find native library: sundog
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
at android.app.ActivityThread.access$600(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4830)
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:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
...
I can't understand why. The app have all necessary libraries in the armeabi, armeabi-v7a and x86 folders. And it has been tested on many devices with different architectures.
android:hasCode="true" option exists.
Also i noticed, that the most of these problematic devices has Rockchip CPU (RK3066, RK2928, RK2926). But not all. The latest one has Huawei K3V2 CPU and a lot of free memory.
Another Native Activity apps (not mine) don't work on the latest device too.
You will need to read the logcat output to see what happened prior to the crash, which prevented the native library from loading. I use Acra for my apps (generates crash reports containing logcat output), but as a quick solution to get the logcat output without implementing a whole crash reporting system, you could use something like this in a test build, and have the user run it:
try
{
Process process = Runtime.getRuntime().exec( "logcat -d" );
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader( process.getInputStream() ) );
StringBuilder log = new StringBuilder();
String line = "";
while( ( line = bufferedReader.readLine() ) != null ) {
log.append( line );
}
// Output available via log.toString().. do whatever with it
}
catch( IOException e ) {}
If you look at the source code for NativeActivty, this exception you are seeing gets thrown in the onCreate() method (see line 171), so if you override that method in a derived class of NativeActivity, you can catch it and grab the logcat output from there. Then you could save the log to a file and have a user with an affected device run the test and email the file to you, for example.
Another good thing about overriding onCreate(), is it will also allow you to reproduce some of what goes on behind the scenes, with more debug logging to help you track down the problem.
Related
Background
Recently I've updated my app, and for some reason Proguard seem to ruin the code I've made, causing crashes on a very specific case, even though I didn't add any additional libraries.
The reason I'm so sure it's Proguard's fault is that when I tested it without exporting it, it ran fine.
The problem
After seeing the crash reports' stack traces (and seeing that it does occur, by myself), I've ran the "proguardgui" tool and chose to retrace using the mapping file.
Sadly, instead of showing the real places that the code failed, it showed the exact same stack. I've tried to export the project again and use a new mapping file that was created by it, but I still get the same obfuscated stack trace.
Not only that, but the exception itself is very problematic: java.lang.NoClassDefFoundError .
Here's the stack trace, though I don't think it's readable:
java.lang.NoClassDefFoundError: com.lb.app_manager.utils.r
at com.lb.app_manager.utils.e.c(Unknown Source)
at com.lb.app_manager.activities.app_list_activity.AppListActivity.onContextItemSelected(Unknown Source)
at android.app.Activity.onMenuItemSelected(Activity.java:2620)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(Unknown Source)
at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(Unknown Source)
at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3864)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:167)
at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
at android.widget.AbsListView$3.run(AbsListView.java:3638)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:133)
at dalvik.system.NativeStart.main(Native Method)
This occurs when I choose to share an app, which, for a very short time should show a progress dialog while running an AsyncTask, and then show a dialog of how you wish to share (just like on the screenshot of the play store link, available here in case you can't see it ).
What I've tried
I've tried to add logs in multiple places, and found out that the AsyncTask runs fine, but it doesn't reach "onPostExecute". I know this since I've put log at the end of "doInBackground" and at the beginning of "onPostExecute" .
This got even weirder, when I removed most of the code of "onPostExecute" and now I have only this:
protected void onPostExecute(final Void result)
{
Log.d("Applog","onPostExecute 0");
super.onPostExecute(result);
Log.d("Applog","onPostExecute 1");
progressDialog.dismiss();
}
It doesn't even reach the first line this way.
In the end, I've decided to merge 2 projects (that I made several versions ago), so that there won't be any Android library project that I made. Only a single one.
I've also removed a library that appears not being used (of Apache commons), but I can't believe this is the cause to the problem (because I didn't use it).
The question
Why do such problems occur?
How can I avoid such a problem in the future?
A NoClassDefFoundError generally points to a problem in the build process: some class that is required doesn't end up in your application.
ProGuard prints out information in the build log about the input jars that it reads and the output jars that it writes. You can also specify
-printconfiguration configuration.txt
to get the complete configuration that ProGuard uses, including input and output. This should help you to find out if all expected input jars are present.
If you are using Eclipse to build your application, you may have run into a synchronization problem that seems to run ProGuard when not all compiled files have been written to disk yet. This mysterious problem has been reported a few times, but it is still unsolved. You should then try Ant or Gradle instead.
I'm using classes from Android's BitmapFun sample code and have been running into a problem with certain devices(My app doesn't crash on all the devices I have tested, but on other peoples).
Note: The version of Android which this happens on has been: 2.3.3-2.3.7, 4.0.3-4.0.4, 4.1 and 4.2
In my Google developer console, I getting the following stack trace:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.question/com.question.ui.question}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
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 dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.question.util.ImageCache.getDiskCacheDir(ImageCache.java:568)
at com.question.util.ImageCache$ImageCacheParams.<init>(ImageCache.java:488)
at com.question.ui.question.onCreate(question.java:58)
at android.app.Activity.performCreate(Activity.java:4479)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
... 11 more
I have looked into this and have found a question with the same problem. I have made some adjustments that are suggested from that answer and same problem still persists.
Code that is causing the problem:
public static File getDiskCacheDir(Context context, String uniqueName) {
// Check if media is mounted or storage is built-in, if so, try and use external cache dir
// otherwise use internal cache dir
final String cachePath =
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ||
!isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() :
context.getCacheDir().getPath();
return new File(cachePath + File.separator + uniqueName);
}
if anyone would know what the issue is here and could explain, that would be of help!
I experienced this issue and discovered my AVD emulator was not configured correctly. Specifically, the null pointer is due to the lack of storage space defined and assigned to the Virtual Device.
To fix the problem create a new or edit your Android Virtual Device with SD Card storage. In Eclipse: Select the Andoid Virtual Device Manager ICON=> Create New=>... Near the bottom of the page is a section called SD Card: Enter a value for SD Card size.
Here is a link that describes how to configure the AVD emulator with the proper storage.
Here is a link that provides a good technical definition why the NullPointerException is generated.
I am trying to start a native app from within an android app (Android Jelly bean (4.1.2)). I am able to start the native app manually from adb, however it does not start from android. The native app is inside AsyncTask and it is started by the doInBackground function. The command I use to start the app inside android is:
process = Runtime.getRuntime().exec("/data/data/MyAppDir/CAL_Android > /data/data/MyAppDir/out.txt 2>&1 &");
I simplified the command as below, but still did not start:
process = Runtime.getRuntime().exec("/data/data/MyAppDir/CAL_Android");
My various attempts at debugging the issue:
Start a simple command, like "touch file.txt" from android. Works
Moved the native app to /data/local/tmp. Did not work.
Changed the execute permission to 777 (rwxrwxrwx). Did not work.
Changed the owner to root apart from that of the app. Did not work.
Tried using a thread (implements Runnable instead of extends AsyncTask). Did not work.
Execute command using "su -c" ("su -c /data/data/MyAppDir/CAL_Android"). Did not work.
Place the command to execute inside a shell script and invoke shell script from Android. Did not work.
I checked the dmesg output and the error I get is:
<7>[14156.022980] CAL_Android: unhandled page fault (11) at 0x0000000c, code 0x017
<1>[14156.023010] pgd = e6204000
<1>[14156.026306] [0000000c] *pgd=b0728831, *pte=00000000, *ppte=00000000
<4>[14156.032777]
<4>[14156.034242] Pid: 9408, comm: CAL_Android
<4>[14156.051821] CPU: 0 Tainted: G W (3.4.0-ge11b2fc-dirty #1)
<4>[14156.061557] PC is at 0x4012aa22
Can someone please tell me what the problem is?
EDIT:
The dmesg output is not correct. After checking a few more times, I am not getting the error message in dmesg. The crash seems to have happened due to a different unknown reason. But I have added an answer to the reason for not being able to start the native app from android. Hopefully this helps someone who faces a similar issue.
I found out why the android app was not able to start the native app, by using the below 2 lines and printing them in the log.
BufferedReader std_input = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader std_error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = std_error.readLine()) != null) {
Log.i(TAG, line);
}
When I used "su -c" before my command, I got this error message:
su: uid <xyz> not allowed to su
and when I did not use "su -c" I got this one instead:
"Cannot open socket: Operation not permitted"
The reason is that, the android app does not have root permission to start the native app and the native app needs root permission to open a socket for sending and receiving data.
Hello I have implemented MonkeyTalk library in my app I used following steps given at https://www.gorillalogic.com/monkeytalk-documentation/monkeytalk-getting-started/install-agent/android.
Through these steps i am successfully able to record and playback steps in monkey talk IDE.
Now issue is when i use my app after installing the library it crashes randomly at several places giving NullPointerException. Log of one such incident is given below:
05-08 19:29:13.661: E/AndroidRuntime(27158): FATAL EXCEPTION: Thread-4790
05-08 19:29:13.661: E/AndroidRuntime(27158): java.lang.NullPointerException
05-08 19:29:13.661: E/AndroidRuntime(27158): at com.gorillalogic.fonemonkey.ActivityManager$2.run(ActivityManager.java:112)
05-08 19:29:13.661: E/AndroidRuntime(27158): at java.lang.Thread.run(Thread.java:856)
Any help to resolve the issue would be greatly appreciated.
I am using Eclipse Juno and Target SDK is 4.2 for development.
I got the same error when I tried to invoke another application (which does not have Monkey Talk Agent) from our application which is integrated with Monkey Talk Agent. So I have added a null pointer check in the monkey talk source code and that fixed the problem.
ActivityManager.cjava - checkIsClipped() function:
// Adding a null pointer check for the case where the application invokes another application that does not have
// MonkeyTalk Agent integrated (for eg: Zxing barcode scanner). In this case the top activity would be null.
catch (NullPointerException e) {
e.printStackTrace();
}
This question already has answers here:
Java.lang.verifyerror how do I fix or even find out the root cause?
(4 answers)
Closed 9 years ago.
Hello I get this error every time I'm trying to open an activity
java.lang.VerifyError: com.karriapps.smartsiddur.Saharit
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Can someone direct me to a solution or a way to check where the problem is coming from
thanks
A VerifyError means your compiled bytecode is referring to something that Android cannot find. In this case, it would appear that you have a reference to a com.karriapps.smartsiddur.Saharit class that Android cannot find.
As CommonsWare mentioned, a VerifyError means that you're trying to reference a class that Dalvik isn't able to load.
It's possible that this class is missing.
It's also possible that you're trying to use framework methods for an API level greater than what's present on the device, and therefore the class is being rejected as invalid.
Try setting your compiler's build level to API Level 7, which corresponds to Android 2.1. (Don't forget to set your AndroidManfest.xml's targetSdkVersion to "7" as well.) This will cause any framework calls that don't exist to raise a compiler error.
You also might want to look at the lines above/below the stack trace you received to see if there's any additional information from the verifier indicating why verification failed.
I found an interesting case that has evidence in runtime. I use:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
So some of new Android 4 capabilities are not implenented in Android 2.3 like this one:
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Ok I can manage it so runtime will not execute it, simply:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
This works well but what about Exception handling?
} catch (NetworkOnMainThreadException nomte) {
// log this exception
} catch (SocketTimeoutException socketTimeoutException) {
// log this exception
}
NetworkOnMainThreadException is not implemented in Android 2.3 so when the class is loaded the exception java.lang.VerifyError occurs.
I ran across this problem today and as CommonsWare mentioned, the issue is that my compiled bytecode was referring to something that no longer existed. But what should you do about it?
Since I'm using Eclipse SDK the simple solution for me was to perform an Eclipse's Project → Clean to remove the pre-compiled byte code in my project that was causing the problem. The Project clean put simply allowed eclipse to perform a full fresh rebuild of my project after the clean.