ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.7k stars 2.24k forks source link

Error accessing "models" first time when AnkiDroid not open #5465

Closed dansanduleac closed 4 years ago

dansanduleac commented 5 years ago
Reproduction Steps
  1. Do not use AnkiDroid for a while, or forcibly kill it
  2. Call com.ichi2.anki.api.AddContentApi.getModelList via its API from another app. The api version used is com.ichi2.anki:api:1.1.0alpha5
  3. I get an IllegalArgumentException back, "Must set a non-null context to create the configuration."
  4. If I try the same action again, it succeeds
Expected Result

The CardContentProvider is correctly loaded and responds successfully when getModelList is called the first time.

Actual Result

I get this exception in logcat. This is on 2.9beta14.

2019-10-12 21:47:46.263 1625-1645/? I/ActivityManager: Start proc 29971:com.ichi2.anki/u0a233 for content provider com.ichi2.anki/.provider.CardContentProvider
2019-10-12 21:47:46.286 29971-29971/? E/com.ichi2.anki: Not starting debugger since process cannot load the jdwp agent.
2019-10-12 21:47:46.294 1625-17835/? I/ActivityManager: DSS on for com.ichi2.anki and scale is 1.0
2019-10-12 21:47:46.311 29971-29971/? I/com.ichi2.anki: The ClassLoaderContext is a special shared library.
2019-10-12 21:47:46.311 29971-29971/? W/com.ichi2.anki: Insufficient pre-allocated space to mmap vdex.
2019-10-12 21:47:46.330 29971-30003/? E/DatabaseUtils: Writing exception to parcel
    java.lang.IllegalArgumentException: Must set a non-null context to create the configuration.
        at androidx.sqlite.db.SupportSQLiteOpenHelper$Configuration$Builder.build(SupportSQLiteOpenHelper.java:4)
        at com.ichi2.libanki.DB.<init>(DB.java:6)
        at com.ichi2.libanki.Storage.Collection(Storage.java:5)
        at com.ichi2.anki.CollectionHelper.getCol(CollectionHelper.java:6)
        at com.ichi2.anki.provider.CardContentProvider.query(CardContentProvider.java:3)
        at android.content.ContentProvider.query(ContentProvider.java:1078)
        at android.content.ContentProvider.query(ContentProvider.java:1170)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:241)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)
        at android.os.Binder.execTransact(Binder.java:739)
Debug info

Refer to the support page if you are unsure where to get the "debug info".

Research

Enter an [ x ] character to confirm the points below:

[x] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid

[x] I have checked the manual and the FAQ and could not find a solution to my issue

[x] I have searched for similar existing issues here and on the user forum

timrae commented 5 years ago

Are you using the latest version of the API?

On Sun., 13 Oct. 2019, 10:12 am Dan Sănduleac, notifications@github.com wrote:

Reproduction Steps

  1. Do not use AnkiDroid for a while, or forcibly kill it
  2. Call com.ichi2.anki.api.AddContentApi.getModelList via its API from another app. The api version used is com.ichi2.anki:api:1.1.0alpha5
  3. I get an IllegalArgumentException back, "Must set a non-null context to create the configuration."

Expected Result

The CardContentProvider is correctly loaded and responds successfully when getModelList is called. Actual Result

I get this exception in logcat. This is on 2.9beta14.

2019-10-12 21:47:46.263 1625-1645/? I/ActivityManager: Start proc 29971:com.ichi2.anki/u0a233 for content provider com.ichi2.anki/.provider.CardContentProvider 2019-10-12 21:47:46.286 29971-29971/? E/com.ichi2.anki: Not starting debugger since process cannot load the jdwp agent. 2019-10-12 21:47:46.294 1625-17835/? I/ActivityManager: DSS on for com.ichi2.anki and scale is 1.0 2019-10-12 21:47:46.311 29971-29971/? I/com.ichi2.anki: The ClassLoaderContext is a special shared library. 2019-10-12 21:47:46.311 29971-29971/? W/com.ichi2.anki: Insufficient pre-allocated space to mmap vdex. 2019-10-12 21:47:46.330 29971-30003/? E/DatabaseUtils: Writing exception to parcel java.lang.IllegalArgumentException: Must set a non-null context to create the configuration. at androidx.sqlite.db.SupportSQLiteOpenHelper$Configuration$Builder.build(SupportSQLiteOpenHelper.java:4) at com.ichi2.libanki.DB.(DB.java:6) at com.ichi2.libanki.Storage.Collection(Storage.java:5) at com.ichi2.anki.CollectionHelper.getCol(CollectionHelper.java:6) at com.ichi2.anki.provider.CardContentProvider.query(CardContentProvider.java:3) at android.content.ContentProvider.query(ContentProvider.java:1078) at android.content.ContentProvider.query(ContentProvider.java:1170) at android.content.ContentProvider$Transport.query(ContentProvider.java:241) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102) at android.os.Binder.execTransact(Binder.java:739)

Debug info

Refer to the support page https://ankidroid.org/docs/help.html if you are unsure where to get the "debug info". Research

Enter an [ x ] character to confirm the points below:

[x] I have read the support page https://ankidroid.org/docs/help.html and am reporting a bug or enhancement request specific to AnkiDroid

[x] I have checked the manual https://ankidroid.org/docs/manual.html and the FAQ https://github.com/ankidroid/Anki-Android/wiki/FAQ and could not find a solution to my issue

[ x] I have searched for similar existing issues here and on the user forum

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AAVQBYTQWY2IP27UZX67ZATQOI4VVA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HRMSUXQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVQBYSJT3JQCMZQCNEZ5U3QOI4VVANCNFSM4JAEMD2Q .

dansanduleac commented 5 years ago

I was using 1.1.0alpha5, but just tested and the same thing happens with 1.1.0alpha6 which I understand to be the latest.

2019年10月13日(日) 3:26 Tim Rae notifications@github.com:

Are you using the latest version of the API?

On Sun., 13 Oct. 2019, 10:12 am Dan Sănduleac, notifications@github.com wrote:

Reproduction Steps

  1. Do not use AnkiDroid for a while, or forcibly kill it
  2. Call com.ichi2.anki.api.AddContentApi.getModelList via its API from another app. The api version used is com.ichi2.anki:api:1.1.0alpha5
  3. I get an IllegalArgumentException back, "Must set a non-null context to create the configuration."

Expected Result

The CardContentProvider is correctly loaded and responds successfully when getModelList is called. Actual Result

I get this exception in logcat. This is on 2.9beta14.

2019-10-12 21:47:46.263 1625-1645/? I/ActivityManager: Start proc 29971:com.ichi2.anki/u0a233 for content provider com.ichi2.anki/.provider.CardContentProvider 2019-10-12 21:47:46.286 29971-29971/? E/com.ichi2.anki: Not starting debugger since process cannot load the jdwp agent. 2019-10-12 21:47:46.294 1625-17835/? I/ActivityManager: DSS on for com.ichi2.anki and scale is 1.0 2019-10-12 21:47:46.311 29971-29971/? I/com.ichi2.anki: The ClassLoaderContext is a special shared library. 2019-10-12 21:47:46.311 29971-29971/? W/com.ichi2.anki: Insufficient pre-allocated space to mmap vdex. 2019-10-12 21:47:46.330 29971-30003/? E/DatabaseUtils: Writing exception to parcel java.lang.IllegalArgumentException: Must set a non-null context to create the configuration. at androidx.sqlite.db.SupportSQLiteOpenHelper$Configuration$Builder.build(SupportSQLiteOpenHelper.java:4) at com.ichi2.libanki.DB.(DB.java:6) at com.ichi2.libanki.Storage.Collection(Storage.java:5) at com.ichi2.anki.CollectionHelper.getCol(CollectionHelper.java:6) at com.ichi2.anki.provider.CardContentProvider.query(CardContentProvider.java:3) at android.content.ContentProvider.query(ContentProvider.java:1078) at android.content.ContentProvider.query(ContentProvider.java:1170) at android.content.ContentProvider$Transport.query(ContentProvider.java:241) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102) at android.os.Binder.execTransact(Binder.java:739)

Debug info

Refer to the support page https://ankidroid.org/docs/help.html if you are unsure where to get the "debug info". Research

Enter an [ x ] character to confirm the points below:

[x] I have read the support page https://ankidroid.org/docs/help.html and am reporting a bug or enhancement request specific to AnkiDroid

[x] I have checked the manual https://ankidroid.org/docs/manual.html and the FAQ https://github.com/ankidroid/Anki-Android/wiki/FAQ and could not find a solution to my issue

[ x] I have searched for similar existing issues here and on the user forum

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AAVQBYTQWY2IP27UZX67ZATQOI4VVA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HRMSUXQ , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAVQBYSJT3JQCMZQCNEZ5U3QOI4VVANCNFSM4JAEMD2Q

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AABWM273BI7BZOCLO7GXUJDQOKBNJA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCMVEA#issuecomment-541379216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABWM2Y7RYVDIQNFKUM6W33QOKBNJANCNFSM4JAEMD2Q .

timrae commented 5 years ago

Well best way is to make a pull request, the idea of the API is just supposed to be a community developed library to reduce the amount of boiler plate code in your application.

On Mon., 14 Oct. 2019, 11:30 am Dan Sănduleac, notifications@github.com wrote:

I was using 1.1.0alpha5, but just tested and the same thing happens with 1.1.0alpha6 which I understand to be the latest.

2019年10月13日(日) 3:26 Tim Rae notifications@github.com:

Are you using the latest version of the API?

On Sun., 13 Oct. 2019, 10:12 am Dan Sănduleac, <notifications@github.com

wrote:

Reproduction Steps

  1. Do not use AnkiDroid for a while, or forcibly kill it
  2. Call com.ichi2.anki.api.AddContentApi.getModelList via its API from another app. The api version used is com.ichi2.anki:api:1.1.0alpha5
  3. I get an IllegalArgumentException back, "Must set a non-null context to create the configuration."

Expected Result

The CardContentProvider is correctly loaded and responds successfully when getModelList is called. Actual Result

I get this exception in logcat. This is on 2.9beta14.

2019-10-12 21:47:46.263 1625-1645/? I/ActivityManager: Start proc 29971:com.ichi2.anki/u0a233 for content provider com.ichi2.anki/.provider.CardContentProvider 2019-10-12 21:47:46.286 29971-29971/? E/com.ichi2.anki: Not starting debugger since process cannot load the jdwp agent. 2019-10-12 21:47:46.294 1625-17835/? I/ActivityManager: DSS on for com.ichi2.anki and scale is 1.0 2019-10-12 21:47:46.311 29971-29971/? I/com.ichi2.anki: The ClassLoaderContext is a special shared library. 2019-10-12 21:47:46.311 29971-29971/? W/com.ichi2.anki: Insufficient pre-allocated space to mmap vdex. 2019-10-12 21:47:46.330 29971-30003/? E/DatabaseUtils: Writing exception to parcel java.lang.IllegalArgumentException: Must set a non-null context to create the configuration. at

androidx.sqlite.db.SupportSQLiteOpenHelper$Configuration$Builder.build(SupportSQLiteOpenHelper.java:4)

at com.ichi2.libanki.DB.(DB.java:6) at com.ichi2.libanki.Storage.Collection(Storage.java:5) at com.ichi2.anki.CollectionHelper.getCol(CollectionHelper.java:6) at

com.ichi2.anki.provider.CardContentProvider.query(CardContentProvider.java:3)

at android.content.ContentProvider.query(ContentProvider.java:1078) at android.content.ContentProvider.query(ContentProvider.java:1170) at android.content.ContentProvider$Transport.query(ContentProvider.java:241) at

android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)

at android.os.Binder.execTransact(Binder.java:739)

Debug info

Refer to the support page https://ankidroid.org/docs/help.html if you are unsure where to get the "debug info". Research

Enter an [ x ] character to confirm the points below:

[x] I have read the support page <https://ankidroid.org/docs/help.html

and am reporting a bug or enhancement request specific to AnkiDroid

[x] I have checked the manual https://ankidroid.org/docs/manual.html and the FAQ https://github.com/ankidroid/Anki-Android/wiki/FAQ and could not find a solution to my issue

[ x] I have searched for similar existing issues here and on the user forum

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <

https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AAVQBYTQWY2IP27UZX67ZATQOI4VVA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HRMSUXQ

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AAVQBYSJT3JQCMZQCNEZ5U3QOI4VVANCNFSM4JAEMD2Q

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AABWM273BI7BZOCLO7GXUJDQOKBNJA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCMVEA#issuecomment-541379216 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AABWM2Y7RYVDIQNFKUM6W33QOKBNJANCNFSM4JAEMD2Q

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AAVQBYST3ZXUTXSFGBPSP5DQOOOQJA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBDB26I#issuecomment-541465977, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVQBYQDPLGYDIHULE2GMATQOOOQJANCNFSM4JAEMD2Q .

hanpingchinese commented 5 years ago

I've also just seen this error message out in the wild (crash report). The exception (in the crash report) is triggered when the client app (my app) calls:

ContentResolver.query(Model.CONTENT_URI, null, null, null, null);

which is called from Fragment.onResume()

I have since been able to reproduce the issue on the latest version of AnkiDroid (2.9alpha80). Do this in Hanping Pro:

So it should be easy to replicate without Hanping Pro. Maybe just try accessing AnkiDroid using the above query after it has just been killed. Reading the OP, this ties in exactly with what he says.

Please note - this is nothing to do with the API (since I'm not using it), instead it's to do with the content provider.

hanpingchinese commented 5 years ago

Okay, so this can be fixed in AnkiDroidApp.java by moving: sInstance = this; up to just after the super.onCreate(); call.

hanpingchinese commented 5 years ago

Any news on this? It's a super-easy fix. I'm sorry I don't have time to make the PR myself.

timrae commented 5 years ago

It's unlikely to be fixed without a PR tbh...

On Mon., 21 Oct. 2019, 1:45 pm Hanping Chinese, notifications@github.com wrote:

Any news on this? It's a super-easy fix. I'm sorry I don't have time to make the PR myself.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ankidroid/Anki-Android/issues/5465?email_source=notifications&email_token=AAVQBYTRU7MDG2LAVMN6AUTQPUXVZA5CNFSM4JAEMD22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBZBFVY#issuecomment-544346839, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVQBYTFUFWYP32LBH6ZO6LQPUXVZANCNFSM4JAEMD2Q .

github-actions[bot] commented 4 years ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

david-allison commented 4 years ago

Fixed in #5557