Cordova app compiles but crashes on run. How to get error report?

落花浮王杯 提交于 2020-01-03 17:12:24

问题


I have a Cordova app that compiles with no errors. However, when I lunch the app to my android device it instantly crashes on startup. I am having a hard time debugging when I do not know what the bug is…

QUESTION: Is there a way to get the error report from this crash?

I usually use chrome to debug my app but that only works if the app is able to load and run on the device.


回答1:


You requested some article about logcat... I'm putting in the answer section since it is too much information for comments :)

DOCS

In case of Android, you can always go to Developer's page.

HERE is the Android's page about logcat

If you use android Studio, you can also check this LINK.

Capturing

Basically, you can capture logcat with following command:

adb logcat

There's a lot of parameters you can add to command which helps you to filter and display the message that you want... This is personal... I always use the command below to get the message timestamp:

adb logcat -v time

You can redirect the output to a file and analyze it in a Text Editor.

Analyzing

If you app is Crashing, you'll get something like:

07-09 08:29:13.474 21144-21144/com.example.khan.abc D/AndroidRuntime: Shutting down VM
07-09 08:29:13.475 21144-21144/com.example.khan.abc E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.khan.abc, PID: 21144
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
     at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
     at android.view.View.performClick(View.java:4848)
     at android.view.View$PerformClick.run(View.java:20262)
     at android.os.Handler.handleCallback(Handler.java:815)
     at android.os.Handler.dispatchMessage(Handler.java:104)
     at android.os.Looper.loop(Looper.java:194)
     at android.app.ActivityThread.main(ActivityThread.java:5631)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-09 08:29:15.195 21144-21144/com.example.khan.abc I/Process: Sending signal. PID: 21144 SIG: 9

This part of the log shows you a lot of information:

  • When the issue happened: 07-09 08:29:13.475

It is important to check when the issue happened... You may find several errors in a log... you must be sure that you are checking the proper messages :)

  • Which app crashed: com.example.khan.abc

This way, you know which app crashed (to be sure that you are checking the logs about your message)

  • Which ERROR: java.lang.NullPointerException

A NULL Pointer Exception error

  • Detailed info about the error: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference

You tried to call method onBackPressed() from a FragmentActivity object. However, that object was null when you did it.

  • Stack Trace: Stack Trace shows you the method invocation order... Sometimes, the error happens in the calling method (and not in the called method).

    at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)

Error happened in file com.example.khan.abc.AudioFragment.java, inside onClick() method at line: 125 (stacktrace shows the line that error happened)

It was called by:

at android.view.View.performClick(View.java:4848)

Which was called by:

at android.view.View$PerformClick.run(View.java:20262)

which was called by:

at android.os.Handler.handleCallback(Handler.java:815)

etc....

Overview

This was just an overview... Not all logs are simple etc... It is just to share the idea and provide a entry-level information to you...

I hope I could help you someway... Regards




回答2:


• Delete the existing folder of MFP Named as : cordova-plugin-mfp (Older Version of MFP Plugin)

• Now run this command and installed the latest version of mfp – “ cordova plugin add cordova-plugin-mfp@8.0.2018112111”

• Now recheck the version by navigating to this path and opening Plugin.xml file inside the mfp folder : D:*******8\FMB_1128_MFP8\plugins\cordova-plugin-mfp\plugins.xml

• You will see the version like this : version="8.0.2018112111" here 8.0 Stands for MFP-8 : 2018: Year of Update: 11:Month of update

By doing these following steps, you will fix the crash issue of the app over android-p version –‘9’



来源:https://stackoverflow.com/questions/38308324/cordova-app-compiles-but-crashes-on-run-how-to-get-error-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!