Skip to content

Commit

Permalink
fix(android): initialize SoLoader with merged libraries on 0.76 (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Sep 18, 2024
1 parent b1bdbf6 commit fffc1d7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
14 changes: 9 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ android {
? "src/devserverhelper-0.73/java"
: "src/devserverhelper-pre-0.73/java",

// TODO: Remove this block when we drop support for 0.72
// https://github.com/facebook/react-native/commit/c3f672cef7d4f287d3d729d33650f917ed132a0c
reactNativeVersion > 0 && reactNativeVersion < v(0, 73, 0)
? "src/reactapplication-pre-0.73/java"
: "src/reactapplication-0.73/java",
// TODO: Remove this block when we drop support for 0.75
// https://github.com/react-native-community/template/commit/f738a366b194dd21d4d2bc14c9215b630714dd70
reactNativeVersion >= v(0, 76, 0)
? "src/reactapplication-0.76/java"
// TODO: Remove this block when we drop support for 0.72
// https://github.com/facebook/react-native/commit/c3f672cef7d4f287d3d729d33650f917ed132a0c
: reactNativeVersion < v(0, 73, 0)
? "src/reactapplication-pre-0.73/java"
: "src/reactapplication-0.73/java",
]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.microsoft.reacttestapp

import android.app.Activity
import android.app.Application
import android.content.Context
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
import com.microsoft.reacttestapp.manifest.Manifest
import com.microsoft.reacttestapp.manifest.ManifestProvider
import com.microsoft.reacttestapp.react.ReactBundleNameProvider
import com.microsoft.reacttestapp.react.TestAppReactNativeHost
import com.microsoft.reacttestapp.support.ReactTestAppLifecycleEvents

class TestApp :
Application(),
ReactApplication {

val bundleNameProvider: ReactBundleNameProvider
get() = reactNativeBundleNameProvider

val manifest: Manifest by lazy {
ManifestProvider.manifest()
}

override val reactHost: ReactHost
get() = getDefaultReactHost(this.applicationContext, reactNativeHost)

override val reactNativeHost: TestAppReactNativeHost
get() = reactNativeHostInternal

private lateinit var reactNativeBundleNameProvider: ReactBundleNameProvider
private lateinit var reactNativeHostInternal: TestAppReactNativeHost

fun reloadJSFromServer(activity: Activity, bundleURL: String) {
reactNativeHostInternal.reloadJSFromServer(activity, bundleURL)
}

override fun onCreate() {
super.onCreate()

SoLoader.init(this, OpenSourceMergedSoMapping)

reactNativeBundleNameProvider = ReactBundleNameProvider(this, manifest.bundleRoot)
reactNativeHostInternal =
TestAppReactNativeHost(this, reactNativeBundleNameProvider)

val eventConsumers = PackageList(this).packages
.filter { it is ReactTestAppLifecycleEvents }
.map { it as ReactTestAppLifecycleEvents }

eventConsumers.forEach { it.onTestAppInitialized() }

reactNativeHostInternal.init(
beforeReactNativeInit = {
eventConsumers.forEach { it.onTestAppWillInitializeReactNative() }
},
afterReactNativeInit = {
eventConsumers.forEach { it.onTestAppDidInitializeReactNative() }
}
)
}
}

val Context.testApp: TestApp
get() = applicationContext as TestApp
1 change: 1 addition & 0 deletions test/pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe("npm pack", () => {
"android/app/src/reactactivitydelegate-0.75/java/com/microsoft/reacttestapp/component/ComponentActivityDelegate.kt",
"android/app/src/reactactivitydelegate-pre-0.72/java/com/microsoft/reacttestapp/component/ComponentActivityDelegate.kt",
"android/app/src/reactapplication-0.73/java/com/microsoft/reacttestapp/TestApp.kt",
"android/app/src/reactapplication-0.76/java/com/microsoft/reacttestapp/TestApp.kt",
"android/app/src/reactapplication-pre-0.73/java/com/microsoft/reacttestapp/TestApp.kt",
"android/app/src/reactinstanceeventlistener-0.68/java/com/microsoft/reacttestapp/compat/ReactInstanceEventListener.kt",
"android/app/src/reactinstanceeventlistener-pre-0.68/java/com/microsoft/reacttestapp/compat/ReactInstanceEventListener.kt",
Expand Down

0 comments on commit fffc1d7

Please sign in to comment.