MyApplication class cannot be cast to com.facebook.react.ReactApplication
See original GitHub issueI am currently working on upgrading RN version of my project from 0.61.5 to 0.63.4. In parallel I am also upgrading reanimated v1.13.2 to v2.3.1. Now the problem is that I don’t have ReactApplication. I build ReactInstanceManager in my activity.
Description
After upgrading I get the following error on app launch
com.example.MyApplication class cannot be cast to com.facebook.react.ReactApplication createUiManager (ReanimatedPackage.java : 70)
Expected behavior
No crash on app start.
Actual behavior & steps to reproduce
Steps: Upgrading from v1 to v2 without any ReactApplication.
Snack or minimal code example
// onCreate of my activity
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setCurrentActivity(this)
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index")
.setJSIModulesPackage((reactApplicationContext, jsContext) -> {
return new ReanimatedJSIModulePackage().getJSIModules(reactApplicationContext, jsContext);
})
.addPackage(new LinearGradientPackage())
.addPackage(new ImagePickerPackage())
.addPackage(new ImageResizerPackage())
.addPackage(new SvgPackage())
.addPackage(new FastImageViewPackage())
.addPackage(new NetInfoPackage())
.addPackage(new LottiePackage())
.addPackage(new RNPermissionsPackage())
.addPackage(new RNGestureHandlerPackage())
.addPackage(new BackgroundTimerPackage())
.addPackage(new RNCWebViewPackage())
.addPackage(new ReanimatedPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
Bundle initialProps = getInitProps();
mReactRootView.startReactApplication(mReactInstanceManager, "example", initialProps);
setContentView(mReactRootView);
Package versions
- React Native: 0.63.4
- React Native Reanimated: 2.3.1
- NodeJS: v14.5.0
- Xcode:
- Java & Gradle: 3.5.3
Affected platforms
- Android
- iOS
- Web
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
android.app.Application cannot be cast to ... - Stack Overflow
react-native upgrade. And I'm getting the error when I try to build the app: android.app.Application cannot be cast to com.facebook.react.ReactApplication.
Read more >Android app application cannot be cast to com facebook react ...
In the Android SDK, the class android.app.Activity is a subclass of android.content.Context. An activity has all the things that any context has —...
Read more >Integration with an Android Fragment - React Native
To use React Native components within Fragments in an existing app ... Ensure your main Application class implements ReactApplication:.
Read more >Fix Application crash Error “android.app.Application cannot be ...
FATAL EXCEPTION, Fix Application crash Error “android.app. Application cannot be cast to”#FataException #RuntimeException #JavaException.
Read more >android.app.Application cannot be cast to ... MyApplication ...
You are implementing an android project with Dagger. We use a custom class that inherits from the class Application (we named MyApplication )...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jkadamczyk In my case, it is as you mentioned. Is an android project that has different android apps where they share this custom React Native activity. I have created a small dummy android project with a custom React Native activity where you can reproduce the issue. You can check it in #2719. Also, I create the PR https://github.com/software-mansion/react-native-reanimated/pull/2863. Let me know if I can help with something else.
Facing the same exact issue, @WFolini can I use your fork for the time being?