Native camera crash on android

Hi,

The app randomly crashes in ionic v3 when trying to take a picture. I’ve googled for this issue and tried various proposed solutions, with no success. Majority of them appeals to include correct information in AndroidManifest.xl, regarding to provider tag, but I think this part is ok.

The crash log is:

}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=null} to activity {io.ionic.starter/io.ionic.starter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4001)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4033)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:193)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6923)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=null} to activity {io.ionic.starter/io.ionic.starter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4597)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3990)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	... 11 more
05-27 18:26:47.498 15690 15690 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:561)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:535)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:377)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:803)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:159)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:359)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.Activity.dispatchActivityResult(Activity.java:7472)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4590)
05-27 18:26:47.498 15690 15690 E AndroidRuntime: 	... 12 more

I’ve created a blank ionic v4 app, and also I’m having the same issue. Sometimes the picture is taked, and sometimes the app is crashing, really strange

The log references to Attempt to invoke virtual method 'android.content.res.XmlResourceParser, but the xml file referenced by AndroidManifest.xml are present, and this issue is not always present, sometimes the device can take a picture, sometimes not!

Any ideas? The strange thing is that the app is crashing with a fresh new app…

I’m experiencing the same issue. Most of the topics in internet say that it is a problem of misconfiguration(different value) between the “android:authorities” names in AndroidManifest.xml and the one used to call getUriForFile() method, but in the case of the cordova camera plugin this name seems to be fine(https://github.com/apache/cordova-plugin-camera/blob/6feaa95559f384468286ab28070030887bac1c5d/src/android/CameraLauncher.java). Any help on this will be appreciated.

The problem seems to be in the way cordova handles slow activities. While looking at the cordova camera plugin https://github.com/apache/cordova-plugin-camera/blob/81b878da5968e27aaf03317753fafd278a3b834e/src/android/CameraLauncher.java#L803
Look here for more details:
[SOLVED] Camera plugin restart App on Android