SecurityException: Failed to find provider null for user 0; on ActiveAndroid on Android 8.0

rindress picture rindress · Aug 28, 2017 · Viewed 19.8k times · Source

I have an app that is using ActiveAndroid and it's been working fine. However; now when I try to save a model to the database I'm getting a SecurityException.

The stack is:

Error saving model java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority 
at android.os.Parcel.readException(Parcel.java:1942) 
at android.os.Parcel.readException(Parcel.java:1888) 
at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:801) 
at android.content.ContentResolver.notifyChange(ContentResolver.java:2046) 
at android.content.ContentResolver.notifyChange(ContentResolver.java:1997) 
at android.content.ContentResolver.notifyChange(ContentResolver.java:1967) 
at com.activeandroid.Model.save(Model.java:162)
[.... local stack removed]

Has anyone else experienced this? Do we need to specify the Content Provider in the AndroidManifest.xml?

Sorry but I do not have an isolated example of this yet. I will work to put something together.

Thanks in advance

Answer

velval picture velval · Dec 6, 2017

As pointed out by @GeigerGeek security changes on Android 26 and above require you to specify the content provider in your manifest.

For ActiveAndroid you can add the below to your Manifest and change your package name.

<provider
  android:name="com.activeandroid.content.ContentProvider"
  android:authorities="<your.package.name>"
  android:enabled="true"
  android:exported="false">
</provider>

If using flavours on your build process you can use below instead:

android:authorities="${applicationId}"

Using ${applicationId} will help in flavor based project structure where application package may be different for each flavors.

For more solutions or info this was taken from here.