B3nedikt/AppLocale

Caused by java.lang.ClassCastException: yb.c cannot be cast to android.app.ContextImpl

smelfungus opened this issue · 4 comments

Hello! Is there a chance that application context wrapping:

    override fun attachBaseContext(newBase: Context) {
        super.attachBaseContext(AppLocale.wrap(newBase))
    }

will not work for some cases, where particular Context implementation is expected internally?
It seems like we're getting the next exceptions with androidx.work because of this:

Fatal Exception: java.lang.RuntimeException: Unable to start receiver androidx.work.impl.background.systemalarm.RescheduleReceiver: java.lang.ClassCastException: yb.c cannot be cast to android.app.ContextImpl
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3107)
       at android.app.ActivityThread.-wrap18(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1611)
       at android.os.Handler.dispatchMessage(Handler.java:110)
       at android.os.Looper.loop(Looper.java:203)
       at android.app.ActivityThread.main(ActivityThread.java:6251)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

(We've got only obfuscated stack trace for now (yb.c), but I'll try to get a normal one if that can help)

It seems like frameworks/base/core/java/android/app/ActivityThread.java is expecting concrete implementation indeed:

image

@dummyco Yeah, you cannot pass a wrapped context here. But this should not be necessary with the current version of AppLocale in the first place. Are you using the latest version of AppLocale?

Yep, for the initial integration, I was referring to the Notes section of the Readme:
https://github.com/B3nedikt/AppLocale#notes
But that's great if the app-level attachBaseContext override is no longer needed.

Yeah, my documentation was outdated here.
If you use a DI tool like koin it is enough now to just pass the wrapped context directly to it, should you use it anywhere to retrieve strings.
I updated my documentation ;)