DSpotDevelopers / declex

DecleX - Declarative Framework for Android, easier and faster coding.
Other
168 stars 25 forks source link

Adding Active Android ContentProvider Stops Local DB Model to be saved. #246

Closed email4shahbaz closed 5 years ago

email4shahbaz commented 5 years ago

All of a sudden my local db model (User) was not being stored in db. It always throw exception "no such table 'users' exists".

I spent almost 10 hours to figure it out but no luck. I was very close to give up, suddenly I found that I have added following ContentProvider tag in AndroidManifest.xml a day ago:

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

When I removed this tag, User_ model started to saved and "users" table existed in local db. Can you please elaborate some useful hint to solve this issue?

email4shahbaz commented 5 years ago

Dear @smaugho , As you always give your swift replies, can you please have a look at this issue and let me know how to solve it. I have published my app which is not working on certain devices (Android 9.0) dues to this issue. My client is pushing me hard.

email4shahbaz commented 5 years ago

@smaugho , I'm sorry, it seems to be solved. I changed android:authorities="${applicationId}" to android:authorities="my.full.package" and it seems to be working.

email4shahbaz commented 5 years ago

@smaugho , I added following ContentProvider in manifest file: `<provider android:name="com.activeandroid.content.ContentProvider" android:authorities="full package name" android:enabled="true" android:exported="false"> </provider> `

and it worked on Android 8.0 but now it is throwing user null exception on all build below Android 6.0. Can you please try any app built using Declex on android device having Android 8.0?

Thanks in advance.

email4shahbaz commented 5 years ago

@smaugho Can you please test any of your Declex app on Android 8.0 (API 26) and confirm if you see the Content Provider issue?

This is becoming very urgent for me to solve this issue. I need your help. Thanks.

smaugho commented 5 years ago

Hi @email4shahbaz. We're a little overloaded on last days, but I'll do my best to check this out. But we'll be removing the support for ActiveAndroid in near future, since long we don't use it, and we're focusing in integration with the Android Architecture Component Library, and from there, with Room as ORM.

We run DecleX in general for any version of Android, including Android 9.0, but the integration with ActiveAndroid is what has not been tested under these versions.

I've checked with old apps (and they build fine, but we'll need to check the migration to higher versions of Gradle and Build tools). Something that we place, compiling against sdkVersion 27 is:

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

Though you say above that you used this already and it didn't work. I'll try to review one of the older apps I have, which uses ActiveAndroid to see if I migrate it to build tools 28.0.0 and the last gradle plugin.

Please, let me know as well if you are able to solve it.

Thanks!

email4shahbaz commented 5 years ago

Apps compile without any issue using content provider: <provider android:name="com.activeandroid.content.ContentProvider" android:authorities="" android:enabled="true" android:exported="false"/>

But when it reaches to a code where is it needed to save data in local db. App is crashed on android below API 26.

If we remove above content provider then App crashes on same point on Android Above API 26

smaugho commented 5 years ago

Maybe you could add the provider, and disable that from within the code for API below 26?

email4shahbaz commented 5 years ago

@smaugho , I already tried that, I added an If condition and disabled that content provider but it still crash. If I remove/comment that provider from manifest file, then it works.

Here is my code:

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { PackageManager pm = getApplicationContext().getPackageManager(); ComponentName componentName = new ComponentName(this, "com.activeandroid.content.ContentProvider"); pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }

Can you please help me in above code.

email4shahbaz commented 5 years ago

@smaugho Can you please help how can I disable it witch code for API below 26? Do you have any code snippet?

email4shahbaz commented 5 years ago

@smaugho , please help me. I cannot publish my app due to this issue. Please please guide me what to do?

smaugho commented 5 years ago

@email4shahbaz this issue seems to be on the core of ActiveAndroid right now:

https://github.com/pardom-zz/ActiveAndroid/issues/535

I highly recommend to migrate to use some ORM like Room or Realm.

We'll be removing support for ActiveAndroid soon on DecleX, since it seems that ActiveAndroid is not being maintained anymore.

email4shahbaz commented 5 years ago

@smaugho Thanks for all your help. I needed to save only one table (users) data into sql db. I decided to use Internal Storage to save user preferences data. This does not require any ContentProvider to be used.

This solved my issue and I can publish my app.

Thanks and again for all your help.