Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): initialize SoLoader with merged libraries on 0.76 #2223

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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