Incompatibility with Custom React Native Integration with Existing Android Apps (Crash on launch)
See original GitHub issueDescription
The last v2.3.0 version introduced an issue that affects Android apps that have a custom React Native integration (see integration-with-existing-apps)
Currently, there is no documentation about how to integrate react-native-reanimated for those kinds of apps. I managed to make it work doing what I show in the code example section, on the main React Native activity.
I was not having any kind of issue with this integration using v2.2.4. After I updated to v2.3.0 I started facing this issue. (See crash on launch capture below)
I also checked where the issue comes from, and as the capture shows, it seems like that it was introduced here. https://github.com/software-mansion/react-native-reanimated/blob/main/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java#L70
It can be seen there that is trying to cast to a ReactApplication when instead the ReactInstanceManager builder in this case handles the application context just as Application
https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java#L155
Expected behavior
Android app should run correctly.
Actual behavior & steps to reproduce
Android app is crashing on launch.

Snack or minimal code example
import com.swmansion.reanimated.ReanimatedJSIModulePackage
....
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication()) // <= Crashing because of this
.setCurrentActivity(this)
.setBundleAssetName("index.android.bundle")
.setJSIModulesPackage(new ReanimatedJSIModulePackage()) // <- Adding reanimated here
.addPackages(packages)
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
...
}
...
}
Example for reproducing this issue
https://github.com/WFolini/custom-rn-with-reanimated
Package versions
- React Native: 64.2
- React Native Reanimated: 2.3.0
- NodeJS: 16.8.0
- Java & Gradle: 1.8.0_292 & 6.8.3
Affected platforms
- Android
- iOS
- Web
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:14 (2 by maintainers)

Top Related StackOverflow Question
Rn can be used to build libraries too. It might not be desirable / possible for certain apps to implement ReactApplication.
Adding -keep to Proguard didn’t fixed it for me. I downgraded to 2.2.4.