// Builds in two contexts: (a) the in-repo kmp Gradle build (AGP 9, module :react-native-bridge) // for CI compile + robolectric tests, and (b) a consumer React Native app via autolinking from // node_modules (typically AGP 8.x + kotlin-android). Keep it free of version-catalog accessors // and project-layout assumptions so both work. plugins { id("com.android.library") } // AGP 9 (in-repo) registers the Kotlin extension built-in; older AGP (consumer RN apps) needs the // standalone plugin, which is on the classpath in any RN app build. if (extensions.findByName("kotlin") == null) { apply(plugin = "org.jetbrains.kotlin.android") } fun isNewArchitectureEnabled() = rootProject.findProperty("newArchEnabled")?.toString() == "true" // New-arch consumer builds need RN codegen (generates NativeNoibuReactNativeSpec from specs/ per // package.json codegenConfig). The plugin is on the classpath in any RN app build; never in-repo. if (isNewArchitectureEnabled()) { apply(plugin = "com.facebook.react") } android { namespace = "com.noibu.mobile.reactnative" compileSdk = 36 defaultConfig { minSdk = 26 buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) } buildFeatures { buildConfig = true } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } testOptions { unitTests { isIncludeAndroidResources = true } } sourceSets { getByName("main") { // The new-arch set extends the codegen'd NativeNoibuReactNativeSpec, which only exists // inside an app build running RN codegen — the in-repo build always compiles legacy. java.srcDirs(if (isNewArchitectureEnabled()) "src/newarch/java" else "src/legacy/java") } } } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach { compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) } dependencies { if (findProject(":sessionreplay") != null) { // In-repo kmp build. implementation(project(":sessionreplay")) implementation(project(":core")) } else { // Consumer app build: the published fat AAR already merges core. // Keep in sync with libs.versions.toml `noibu-session-replay`. implementation("com.noibu.mobile:session-replay-android:1.0.0-rc.1") } // Like the old SDK's `com.facebook.react:react-native:+`, RN is resolved from Maven Central — // compileOnly: the consumer app provides react-android at runtime. 0.86 for the new-arch // drawable classes (ReactDrawableStyles); hosts on older RN degrade there, never link-crash. compileOnly("com.facebook.react:react-android:0.86.0") // OkHttpClientProvider factory injection (NetworkInterceptor install). implementation("com.squareup.okhttp3:okhttp:4.12.0") testImplementation("junit:junit:4.13.2") testImplementation("org.robolectric:robolectric:4.12.2") testImplementation("com.facebook.react:react-android:0.86.0") }