Search code examples
androidcordovacrashcordova-pluginsandroid-support-library

Android crashes due to android.support.v4.content.FileProvider.parsePathStrategy


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>

Solution

  • 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