how to make my phonegap android app crash?

前端 未结 9 1320
萌比男神i
萌比男神i 2021-02-05 03:27

I am developing a crash reporter plugin for phonegap android apps. For the testing purpose, I have to make my application crash & \"Unfortunately, application has stopped\"

相关标签:
9条回答
  • 2021-02-05 03:35

    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:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        this.postMessage("onCreateOptionsMenu", menu);
        throw new RuntimeException();
    } 
    

    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.

    0 讨论(0)
  • 2021-02-05 03:35

    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.

    0 讨论(0)
  • 2021-02-05 03:35

    I strongly believe infinite loops won't work in this case. When you use it with PhoneGap, javascript is only a (safe) script language that cannot generate system-driven exceptions.

    The best method is to run some native codes (problematic codes) under the help of another PhoneGap plugin. For example, you can do division by zero in objective-c and java native codes.

    0 讨论(0)
  • 2021-02-05 03:41
    1. try download any file more that 100MB(my app got stuck in low end androids). You can even do that in loops.

    2. Use canvas and drop some random 3d figures.

    3. app an alert message in a loop of 1000.

    0 讨论(0)
  • 2021-02-05 03:48

    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 ;)

    0 讨论(0)
  • 2021-02-05 03:52

    Usually a halt in execution, intentional or not, can cause android to think the app has crashed. Try wrapping your code in something like setTimeout(function() { your code }, 60000) to delay execution by a minute.

    Or, try making an ajax request that will time out.

    0 讨论(0)
提交回复
热议问题