Trying with the initial impl of the Android support, I was able to get a demo working on my Android16 phone, but when attempting to use the same demo on an older FireOS device (Android 9), I was seeing a crash.
Logs:
03-13 09:59:11.019 17465 17465 E AndroidRuntime: Process: com.demo, PID: 17465
03-13 09:59:11.019 17465 17465 E AndroidRuntime: java.lang.StackOverflowError: stack size 8MB
03-13 09:59:11.019 17465 17465 E AndroidRuntime: at android.content.Context.registerComponentCallbacks(Context.java:546)
03-13 09:59:11.019 17465 17465 E AndroidRuntime: at android.content.Context.registerComponentCallbacks(Context.java:546)
...<truncated>
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.content.Context.registerComponentCallbacks(Context.java:546)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.content.Context.registerComponentCallbacks(Context.java:546)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.content.Context.registerComponentCallbacks(Context.java:546)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at com.facebook.react.MemoryPressureRouter.<init>(MemoryPressureRouter.kt:21)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at com.facebook.react.runtime.ReactHostImpl.<init>(ReactHostImpl.java:197)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at com.facebook.react.runtime.ReactHostImpl.<init>(ReactHostImpl.java:172)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at com.facebook.react.runtime.ReactHostImpl.<init>(ReactHostImpl.java:154)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at io.callstack.rnsandbox.SandboxReactNativeDelegate.loadReactNativeView(SandboxReactNativeDelegate.kt:117)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at io.callstack.rnsandbox.SandboxReactNativeViewManager.loadReactNativeView(SandboxReactNativeViewManager.kt:192)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at io.callstack.rnsandbox.SandboxReactNativeViewManager.createViewInstance$lambda$1(SandboxReactNativeViewManager.kt:37)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at io.callstack.rnsandbox.SandboxReactNativeViewManager.$r8$lambda$hp-73FulWfus-cg8F0BatNT40fQ(Unknown Source:0)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at io.callstack.rnsandbox.SandboxReactNativeViewManager$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at io.callstack.rnsandbox.SandboxReactNativeView.onAttachedToWindow(SandboxReactNativeView.kt:26)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.view.View.dispatchAttachedToWindow(View.java:18347)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.view.ViewGroup.addViewInner(ViewGroup.java:5077)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.view.ViewGroup.addView(ViewGroup.java:4865)
03-13 09:59:12.115 17465 17465 E AndroidRuntime: at android.view.ViewGroup.addView(ViewGroup.java:4805)
What I believe is happening for the crash:
SandboxContextWrapper.getApplicationContext() returns this, which causes infinite recursion when MemoryPressureRouter (called during ReactHostImpl init) invokes context.registerComponentCallbacks().
On older android versions, Context.registerComponentCallbacks() delegates to getApplicationContext().registerComponentCallbacks(), and since getApplicationContext() points back to the same wrapper, it loops forever until the stack overflows.
Seems to be due to a change between the register component callbacks works between android 12 and 13:
https://developer.android.com/reference/android/content/ContextWrapper#registerComponentCallbacks(android.content.ComponentCallbacks)
Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called. Note that you must be sure to use unregisterComponentCallbacks(ComponentCallbacks) when appropriate in the future; this will not be removed for you.
After Build.VERSION_CODES.TIRAMISU (Android 13) the ComponentCallbacks will be registered to the base Context, and can be only used after attachBaseContext(Context). Users can still call to getApplicationContext().registerComponentCallbacks(ComponentCallbacks) to add ComponentCallbacks to the base application.
Trying with the initial impl of the Android support, I was able to get a demo working on my Android16 phone, but when attempting to use the same demo on an older FireOS device (Android 9), I was seeing a crash.
Logs:
What I believe is happening for the crash:
SandboxContextWrapper.getApplicationContext()returns this, which causes infinite recursion when MemoryPressureRouter (called during ReactHostImpl init) invokescontext.registerComponentCallbacks().On older android versions,
Context.registerComponentCallbacks()delegates togetApplicationContext().registerComponentCallbacks(), and sincegetApplicationContext()points back to the same wrapper, it loops forever until the stack overflows.Seems to be due to a change between the register component callbacks works between android 12 and 13:
https://developer.android.com/reference/android/content/ContextWrapper#registerComponentCallbacks(android.content.ComponentCallbacks)