question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatibility with Custom React Native Integration with Existing Android Apps (Crash on launch)

See original GitHub issue

Description

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. image

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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
saghulcommented, Feb 9, 2022

Rn can be used to build libraries too. It might not be desirable / possible for certain apps to implement ReactApplication.

2reactions
halaeicommented, Dec 15, 2021

Adding -keep to Proguard didn’t fixed it for me. I downgraded to 2.2.4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

software-mansion/react-native-reanimated@3fb35cf - GitHub
Incompatibility with Custom React Native Integration with Existing Android Apps (Crash on launch) #1040. Sign in to view logs · Sign in to...
Read more >
Behavior changes: Apps targeting Android 12
Android 12 changes the appearance and behavior of fully custom notifications. Previously, custom notifications were able to use the entire notification area and ......
Read more >
App Center Crashes for React Native - Microsoft Learn
App Center supports Breakpad crashes from Android NDK in a React Native apps. Follow the normal setup steps above, and in your MainActivity.java ......
Read more >
Using Sentry - Expo Documentation
Native crash reporting is not available with the classic build system ( expo build:[ios|android] ), but is available via EAS Build.
Read more >
React Native app crashes at start without error message
Try upgrading react-native-reanimated to 2.10.0 or newer if you use it. I had the same issue with 2.9.1. · I'm struggling with latest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found