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

java.lang.ClassCastException: com.phrase.android.sdk.inject.PhraseContextWrapper cannot be cast to android.app.ContextImpl #25

Closed
mzsanford opened this issue Feb 5, 2021 · 6 comments

Comments

@mzsanford
Copy link

I'm testing Phrase integration and my app has a BroadcastReceiver registered in the manifest.xml like so:

       <receiver android:name="com.redacted.AppUpdatedReceiver">
            <intent-filter>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
            </intent-filter>
        </receiver>

And the class itself is a simple subclass of BroadcastReceiver implementing onReceive. If I comment this out of the manifest.xml everything works fine. When I have this enabled my app crashes soon after launch with:

    java.lang.RuntimeException: Unable to instantiate receiver com.redacted.AppUpdatedReceiver: java.lang.ClassCastException: com.phrase.android.sdk.inject.PhraseContextWrapper cannot be cast to android.app.ContextImpl
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:4012)
        at android.app.ActivityThread.access$1400(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7660)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.ClassCastException: com.phrase.android.sdk.inject.PhraseContextWrapper cannot be cast to android.app.ContextImpl
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3996)
        at android.app.ActivityThread.access$1400(ActivityThread.java:237) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7660) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

Device: Google Pixel 5, Android 11

@theSoenke
Copy link
Contributor

Hi @mzsanford, the Android SDK is expecting an exact instance of ContextImpl in some places, which are causing this issue. For now, I would recommend removing Phrase.wrapApplicationContext from your Application class. We'll also likely release a new version soon which will remove this method.

@erdincozden
Copy link

Some problem : Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassCastException: com.phrase.android.sdk.inject.PhraseContextWrapper cannot be cast to android.app.ContextImpl

@theSoenke
Copy link
Contributor

Hey, thanks for your patience. We have now found a solution to be able to wrap the application context in an Application class. The fix is released in version 3.0.2. This should resolve the cast exception.

@jerepious
Copy link

jerepious commented Sep 12, 2023

Hello,

We have the same issue that occurs on the latest Phrase app version of Android SDK 3.5.0 & 3.6.0 , I noticed a crash the first time of running the app with the SDK integrated on release Build variants.
: java.lang.RuntimeException: Unable to instantiate receiver
com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassCastException: com.phrase.android.sdk.inject.PhraseContextWrapper
cannot be cast to android.app.ContextImpl

@theSoenke theSoenke reopened this Sep 12, 2023
@drachim-dev
Copy link

Same issue here:

android.app.ActivityThread.handleReceiver
ActivityThread.java, line 4413
java.lang.ClassCastException: com.phrase.android.sdk.inject.PhraseContextWrapper cannot be cast to android.app.ContextImpl

@theSoenke
Copy link
Contributor

Hi, this turned out to be a regression and has should be resolved in version 3.7.1 https://github.com/phrase/phrase-android/releases/tag/3.7.1

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

5 participants