How To Make My Phonegap Android App Crash?
Solution 1:
Crash by pressing menu button:
You cannot make the app crash from a plugin or javascript call as the exceptions are handled internally. If you want to make the app crash in android you can edit CordovaActivity.java in Android platform. Change onCreateOptionsMenu as shown:
@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
this.postMessage("onCreateOptionsMenu", menu);
thrownewRuntimeException();
}
Press the menu button and app will crash & "Unfortunately, application has stopped" window will be displayed.
Crash by calling some native function from Javascript:
Write an Android native plugin for Phonegap. Refer http://docs.phonegap.com/en/3.0.0/guide_platforms_android_plugin.md.html#Android%20Plugins for plugin creation. Throw exception inside execute method. This will be handled in the parent layer(Thats why you can see logs about crash in the console), So please do following changes to make the app crash.(Both the classes belong to org.apache.cordova package)
- Remove
catch (Exception e){}
block in execHelper method of pluginManager classs. Remove
catch (Throwable e) {}
block in exec method of ExposedJsApi class.With this change I am able to crash the application from javascript call.
Solution 2:
If an app would run like a webpage, a infinite loop might take some time to cause a crash, but should work. Just remember to remove it after testing. Because it causes an exception, and times out the program, the crash should be properly invoked if something possible harmful is used in it. Do something like this:
while(true){ eval("9.99999e+5000 / Infinity"); }
Because we aren't editing a variable, we will prevent the out of memory
error.
If this doesn't work, refer to @Aaron D's answer, and if that doesn't work, refer to @kumar's answer.
Solution 3:
Unfortunately, JS exceptions are handled by the WebView and even native plugins run in their own separate thread, and will not crash the main Application thread if you raise an exception there (this may not be true for hybrid applications). So you need to hook into the main activity and cause it to throw an Exception on the main thread.
Subclass the CordovaActivity
class and override the plugin messaging method:
@OverridepublicObjectonMessage(String id, Object data) {
if ("crashApp".equals(id)) {
thrownewException();
}
super(id, data);
}
Write an Android native plugin for Phonegap as per this answer. What it does doesn't matter, but when you message it from the Javascript you should use the id 'crashApp' which should be picked up by your overridden method in the CordovaActivity
subclass, and raise the Exception on the main thread.
. Then you can message your plugin using this id whenever you have a Javascript exception by overriding the window.onerror
function:
window.onerror = functionmyFunction(errorMsg, url, lineNumber) {
/* call Android native function to throw Exception */ ;
returnfalse; }
This will throw all Javascript errors down into your Java code where they can raise the ANR dialog (and you can pass debugging information with it too).
Solution 4:
You can make your cordova/ phonegap application crash by removing the permissions from the AndroindManifest.xml
file but still using them inside the app, these kind of exceptions mostly crash your application.
please note that (depending on your project structure) modifying the AndroindManifest.xml
file itself, it may be regenerated and change back to its correct state so you're gonna need to remove permission lines and then change the Androind.json
file in the plugins
folder befor build, appropriately to make your changes take effect.
I tested this process and it definitely works! :D
hope it helps, mim ;)
Solution 5:
try download any file more that 100MB(my app got stuck in low end androids). You can even do that in loops.
Use canvas and drop some random 3d figures.
app an alert message in a loop of 1000.
Post a Comment for "How To Make My Phonegap Android App Crash?"