Skip to content

Commit 54cea4a

Browse files
committed
fix(android): initialize SoLoader with merged libraries on 0.76
1 parent fe2631d commit 54cea4a

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

android/app/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,15 @@ android {
249249
? "src/devserverhelper-0.73/java"
250250
: "src/devserverhelper-pre-0.73/java",
251251

252-
// TODO: Remove this block when we drop support for 0.72
253-
// https://github.com/facebook/react-native/commit/c3f672cef7d4f287d3d729d33650f917ed132a0c
254-
reactNativeVersion > 0 && reactNativeVersion < v(0, 73, 0)
255-
? "src/reactapplication-pre-0.73/java"
256-
: "src/reactapplication-0.73/java",
252+
// TODO: Remove this block when we drop support for 0.75
253+
// https://github.com/react-native-community/template/commit/f738a366b194dd21d4d2bc14c9215b630714dd70
254+
reactNativeVersion >= v(0, 76, 0)
255+
? "src/reactapplication-0.76/java"
256+
// TODO: Remove this block when we drop support for 0.72
257+
// https://github.com/facebook/react-native/commit/c3f672cef7d4f287d3d729d33650f917ed132a0c
258+
: reactNativeVersion < v(0, 73, 0)
259+
? "src/reactapplication-pre-0.73/java"
260+
: "src/reactapplication-0.73/java",
257261
]
258262
}
259263

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.microsoft.reacttestapp
2+
3+
import android.app.Activity
4+
import android.app.Application
5+
import android.content.Context
6+
import com.facebook.react.PackageList
7+
import com.facebook.react.ReactApplication
8+
import com.facebook.react.ReactHost
9+
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
10+
import com.facebook.react.soloader.OpenSourceMergedSoMapping
11+
import com.facebook.soloader.SoLoader
12+
import com.microsoft.reacttestapp.manifest.Manifest
13+
import com.microsoft.reacttestapp.manifest.ManifestProvider
14+
import com.microsoft.reacttestapp.react.ReactBundleNameProvider
15+
import com.microsoft.reacttestapp.react.TestAppReactNativeHost
16+
import com.microsoft.reacttestapp.support.ReactTestAppLifecycleEvents
17+
18+
class TestApp :
19+
Application(),
20+
ReactApplication {
21+
22+
val bundleNameProvider: ReactBundleNameProvider
23+
get() = reactNativeBundleNameProvider
24+
25+
val manifest: Manifest by lazy {
26+
ManifestProvider.manifest()
27+
}
28+
29+
override val reactHost: ReactHost
30+
get() = getDefaultReactHost(this.applicationContext, reactNativeHost)
31+
32+
override val reactNativeHost: TestAppReactNativeHost
33+
get() = reactNativeHostInternal
34+
35+
private lateinit var reactNativeBundleNameProvider: ReactBundleNameProvider
36+
private lateinit var reactNativeHostInternal: TestAppReactNativeHost
37+
38+
fun reloadJSFromServer(activity: Activity, bundleURL: String) {
39+
reactNativeHostInternal.reloadJSFromServer(activity, bundleURL)
40+
}
41+
42+
override fun onCreate() {
43+
super.onCreate()
44+
45+
SoLoader.init(this, OpenSourceMergedSoMapping)
46+
47+
reactNativeBundleNameProvider = ReactBundleNameProvider(this, manifest.bundleRoot)
48+
reactNativeHostInternal =
49+
TestAppReactNativeHost(this, reactNativeBundleNameProvider)
50+
51+
val eventConsumers = PackageList(this).packages
52+
.filter { it is ReactTestAppLifecycleEvents }
53+
.map { it as ReactTestAppLifecycleEvents }
54+
55+
eventConsumers.forEach { it.onTestAppInitialized() }
56+
57+
reactNativeHostInternal.init(
58+
beforeReactNativeInit = {
59+
eventConsumers.forEach { it.onTestAppWillInitializeReactNative() }
60+
},
61+
afterReactNativeInit = {
62+
eventConsumers.forEach { it.onTestAppDidInitializeReactNative() }
63+
}
64+
)
65+
}
66+
}
67+
68+
val Context.testApp: TestApp
69+
get() = applicationContext as TestApp

test/pack.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe("npm pack", () => {
9595
"android/app/src/reactactivitydelegate-0.75/java/com/microsoft/reacttestapp/component/ComponentActivityDelegate.kt",
9696
"android/app/src/reactactivitydelegate-pre-0.72/java/com/microsoft/reacttestapp/component/ComponentActivityDelegate.kt",
9797
"android/app/src/reactapplication-0.73/java/com/microsoft/reacttestapp/TestApp.kt",
98+
"android/app/src/reactapplication-0.76/java/com/microsoft/reacttestapp/TestApp.kt",
9899
"android/app/src/reactapplication-pre-0.73/java/com/microsoft/reacttestapp/TestApp.kt",
99100
"android/app/src/reactinstanceeventlistener-0.68/java/com/microsoft/reacttestapp/compat/ReactInstanceEventListener.kt",
100101
"android/app/src/reactinstanceeventlistener-pre-0.68/java/com/microsoft/reacttestapp/compat/ReactInstanceEventListener.kt",

0 commit comments

Comments
 (0)