4

I was just checking the ANRs & Crashes for one of my Android apps in the Google Play console.

I randomly chose to turn on the "Show hidden" switch on the Crashes tab (no idea what hidden vs not hidden means and it's the first time I turned it on) and I saw at the top of the list a crash which is happening hundreds of times per day and affecting hundreds of users.

enter image description here

I gather from the stack trace it's related to the Android Support Library, but I have no idea what the cause is and so far Googling the stack trace lines hasn't turned up anything useful.

It only started happening when I released a new minor app version on March 22, but from what I can see in the repo history, the changes I made are very minor so don't explain this.

Here's the stacktrace:

java.lang.NullPointerException in android.support.v4.content.FileProvider.parsePathStrategy

java.lang.RuntimeException: 
  at android.app.ActivityThread.installProvider (ActivityThread.java:6643)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:6185)
  at android.app.ActivityThread.handleInstallProvider (ActivityThread.java:3452)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1939)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:193)
  at android.app.ActivityThread.main (ActivityThread.java:6923)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:870)
Caused by: java.lang.NullPointerException: 
  at android.support.v4.content.FileProvider.parsePathStrategy (FileProvider.java:584)
  at android.support.v4.content.FileProvider.getPathStrategy (FileProvider.java:558)
  at android.support.v4.content.FileProvider.attachInfo (FileProvider.java:376)
  at android.app.ActivityThread.installProvider (ActivityThread.java:6638)

I think this is the line being referred to in the stack trace in the Android Support library.

Any ideas what could be the cause?

Update

Some more digging and I find these 3 entries in AndroidManifest.xml inside <application>:

<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
  <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
</provider>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.emailcomposer.Provider">
  <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/emailcomposer_provider_paths"/>
</provider>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.plugin.notification.util.AssetProvider">
  <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/localnotification_provider_paths"/>

There are 3 corresponding files in res/xml/:

  • provider_paths.xml
  • localnotification_provider_paths.xml
  • emailcomposer_provider_paths.xml

This is an Apache Cordova project, so those entries are genenerated by:

Each XML file contains the same contents:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Check this if it helps https://stackoverflow.com/questions/45973746/missing-android-support-file-provider-paths-meta-data it is similar to your problem. – Shoaib Mirza Apr 01 '19 at 20:27
  • check this https://stackoverflow.com/questions/46550472/fileprovider-geturiforfile-returns-nullpointerexception – fancyyou Apr 02 '19 at 02:20
  • Thanks, but while those posts refer to similar errors, they are not the same. I should also emphasise that the crashes appear intermittent or caused by an edge case: I'm unable to reproduce them on test devices and most users (98%) are unaffected. – DaveAlden Apr 02 '19 at 09:31

1 Answers1

3

I finally tracked down the cause of these crashes which appears to be caused by a collision of provider authority names.

I changed the names of the authorities to be unique, and now having released this as an updated in the Play Store, the crashes have stopped being reported in this latest version:

android:authorities="${applicationId}.camera.provider
android:authorities="${applicationId}.emailcomposer.provider
android:authorities="${applicationId}.localnotification.provider

For reference I found this information in this Github issue: https://github.com/katzer/cordova-plugin-local-notifications/issues/1664

DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Thank you for taking care of this! Really helpful investigation. – Kosh Apr 10 '19 at 19:50
  • @DaveAlden thanks for providing this answer, just a quick question, when making this change in the Manifest file did you also have to change the plugin code elsewhere? Looks like I need to change the CameraLauncher.java & AssetUtil.java files if I change the authorities, is this correct? – Simon L. Brazell May 04 '19 at 12:42
  • 1
    Yes the source code needs to change too, for example see [this commit](https://github.com/dpa99c/cordova-plugin-local-notifications/commit/eb1fb457bc47c430a8a528313322ecd697f4f6b5) – DaveAlden May 04 '19 at 14:58