Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.save failing on Android O device #536

Open
JacobVanAssche opened this issue Sep 1, 2017 · 27 comments
Open

.save failing on Android O device #536

JacobVanAssche opened this issue Sep 1, 2017 · 27 comments

Comments

@JacobVanAssche
Copy link

I recently just updated my device to Android O and now the .save methods no longer work.

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)

@agonper
Copy link

agonper commented Sep 4, 2017

Same problem here, hope gets fixed soon

@zuiaichiyu
Copy link

same problem

@uncledoc
Copy link

uncledoc commented Sep 5, 2017

on latest android emulator works fine for me

@JacobVanAssche
Copy link
Author

@uncledoc You're using Android 8.0.0 on the emulator? I'm still getting the same error on an emulator.

@pavelannin
Copy link

pavelannin commented Sep 6, 2017

Hi.
Same problem.
I set compileSdkVersion = 25 and targetSdkVersion = 25. On Android O (API 26) it works.
This is not a solution, it's a HotFix.
Waiting for a solution from the developers.

@tzutalin
Copy link

tzutalin commented Sep 7, 2017

Met the same issue on Android 8

@JacobVanAssche
Copy link
Author

I think my plan is to convert over to Google's new Room Persistence Library instead of using ActiveAndroid. It doesn't look like ActiveAndroid is maintained at all anymore.

@martino2k6
Copy link

This can be fixed by adding

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

to your manifest file.

But I'd agree with @JacobVanAssche, if you can then move to a different library as this one hasn't been updated for a while and probably won't be.

@martiwi
Copy link

martiwi commented Sep 24, 2017

Importing the source code into your project and compile it with API 26 solved it.

@giperwlad
Copy link

In my case it was fixed as following steps:

  1. clone source code to my ap as module
  2. hardcode sAuthority string field in class com.activeandroid.content.ContentProvider:
    private static final String sAuthority="your.package.name";
  3. Declare provider in manifest

@azizimusa
Copy link

@martino2k6 solution work for me.

@ricardomorsch
Copy link

if your package is different from your applicationId then you should use the applicationId

<provider
            android:name="com.activeandroid.content.ContentProvider"
            android:authorities="${applicationId}"
            android:exported="false" />

@adrianbudzynski
Copy link

@martino2k6 & @ricardomorsch
Yours solution is good but not in all cases. When project have defined model classes in java source code through addModelClasses configuration method application will still be crashing cause model classes wont be loaded through that configuration. In that situation You need to move model definition to the AndroidManifest.xml file.

@joshuatam
Copy link

joshuatam commented Nov 15, 2017

@adrianbudzynski
I get it work by extending com.activeandroid.content.ContentProvider

AndroidManifest.xml

<provider
        android:name=".content.DatabaseContentProvider"
        android:authorities="${applicationId}"
        android:exported="false" />

DatabaseContentProvider.java

...
import com.activeandroid.content.ContentProvider;
...

public class DatabaseContentProvider extends ContentProvider {

	@Override
	protected Configuration getConfiguration() {
		Configuration.Builder builder = new Configuration.Builder(getContext());
		builder.addModelClass(SomeModel.class);
		builder.addModelClass(OtherModel.class);
		return builder.create();
	}
}

@azizimusa
Copy link

Solution by @joshuatam is working.

To get a context at this line Configuration.Builder builder = new Configuration.Builder(context); inside DatabaseContentProvider. Can just use getContext()

@joshuatam
Copy link

@azizimusa Thanks, corrected.

@PareshMayani
Copy link

Thanks @joshuatam, your solution is working.

@ImangazalievM
Copy link

ImangazalievM commented Dec 2, 2017

Hello, guys! You can use my library - https://github.com/ImangazalievM/ReActiveAndroid. I forked the ActiveAndroid and fixed all bugs. It works fine on Android O and other versions.

@JacobVanAssche @agonper @zuiaichiyu @anninpavel @azizimusa @PareshMayani @joshuapinter @adrianbudzynski @martino2k6 @tzutalin

@erhanbicer
Copy link

Thanks! @joshuatam is working

@liupeng826
Copy link

liupeng826 commented Apr 29, 2018

@joshuatam
issue again when add 1 column when I follow the Schema-migrations
https://github.com/pardom-zz/ActiveAndroid/wiki/Schema-migrations

    <meta-data android:name="AA_DB_NAME" android:value="NALocator.db" />
    <meta-data android:name="AA_DB_VERSION" android:value="2" />
    <meta-data android:name="AA_MODELS"
    android:value="com.volvo.it.mobile.locator.core.entity.Location, com.volvo.it.mobile.locator.core.entity.LocationService" />

what need i to do more? do you have an worked sample?

@liupeng826
Copy link

@ImangazalievM do i need to change a lot if use ReActiveAndroid?

@ImangazalievM
Copy link

@liupeng826 No. If you want to migrate to ReActiveAndroid, read this article https://imangazalievm.gitbooks.io/reactiveandroid/migration-from-activeandroid.html

@NagoLazaro
Copy link

@joshuatam Your solution worked for me perfectly. Thanks!

@fajaranugrah
Copy link

So what to do to solve this problem? I have never used ContentProvider for all classes but one class has already created the code but still gets the report error
Thank you

@ImangazalievM
Copy link

@fajaranugrah you can start using https://github.com/ImangazalievM/ReActiveAndroid. I fixed all bugs and it works on Android O. If you want to migrate to ReActiveAndroid, please read this article https://imangazalievm.gitbooks.io/reactiveandroid/migration-from-activeandroid.html

@deiry
Copy link

deiry commented Mar 22, 2019

@joshuatam Thank you for help! It's works perfectly.

@joshuapinter
Copy link
Contributor

A nifty trick if you don't want to extend the ContentProvider to put your dynamic configuration in there, is to just dispose() of the ActiveAndroid database connection on your app initialization and just reinitialize it with your specific configuration.

This allows you to keep the normal ContentProvider as is in the AndroidManifest.xml:

<provider
  android:name="com.activeandroid.content.ContentProvider"
  android:authorities="${applicationId}"
  android:enabled="true"
  android:exported="false">
</provider>

And then just do something like this in your App's onCreate() method:

// Close existing database connection, if it exists.
try {
  ActiveAndroid.dispose();
}
catch( NullPointerException ignored ) {}

Configuration databaseConfiguration = new Configuration.Builder( this )
  .setDatabaseName( "MyDatabase" )
  .setDatabaseVersion( 100 )
  .setModelClasses( MyModel.class )
  .create();

ActiveAndroid.initialize( databaseConfiguration );

This does mean that you will have an Application.db file in your data/data/databases/ directory (from ActiveAndroid initializing with the ContentProvider) but I think that's a minor drawback in order to have a clean, dynamic configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests