diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 89fff09bd7b4fe..fb70693013d9e5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -729,12 +729,22 @@ private void attachToReactInstanceManager() { // React Native requires that the RootView id be managed entirely by React Native, and will // crash in addRootView/startSurface if the native View id isn't set to NO_ID. + + // This behavior can not be guaranteed in hybrid apps that have a native android layer over + // which reactRootViews are added and the native views need to have ids on them in order to + // work. + // Hence this can cause unnecessary crashes at runtime for hybrid apps. + // So converting this to a soft exception such that pure react-native devs can still see the + // warning while hybrid apps continue to run without crashes + if (getId() != View.NO_ID) { - throw new IllegalViewOperationException( - "Trying to attach a ReactRootView with an explicit id already set to [" - + getId() - + "]. React Native uses the id field to track react tags and will overwrite this" - + " field. If that is fine, explicitly overwrite the id field to View.NO_ID."); + ReactSoftExceptionLogger.logSoftException( + TAG, + new IllegalViewOperationException( + "Trying to attach a ReactRootView with an explicit id already set to [" + + getId() + + "]. React Native uses the id field to track react tags and will overwrite this" + + " field. If that is fine, explicitly overwrite the id field to View.NO_ID.")); } try {