diff --git a/android/build.gradle b/android/build.gradle index ba756ff..d1e22a0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,7 +1,11 @@ -buildscript { - // Buildscript is evaluated before everything else so we can't use getExtOrDefault - def kotlinVersion = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["ApiVideoLivestream_kotlinVersion"] +import com.android.Version + +import java.nio.file.Paths +buildscript { + ext.safeExtGet = {prop -> + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : project.properties['ApiVideoLiveStream_' + prop] + } repositories { google() mavenCentral() @@ -10,54 +14,38 @@ buildscript { dependencies { classpath "com.android.tools.build:gradle:8.1.1" // noinspection DifferentKotlinGradleVersion - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion')}" } } -def isNewArchitectureEnabled() { - return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +def getExtOrDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ApiVideoLivestream_" + name] } -apply plugin: "com.android.library" -apply plugin: "kotlin-android" - -import groovy.json.JsonSlurper - -// https://github.com/callstack/react-native-builder-bob/discussions/359 -def registrationCompat = { - def reactNativeManifest = file("$projectDir/../node_modules/react-native/package.json").exists() - ? file("$projectDir/../node_modules/react-native/package.json") // developer mode, to run example app - : file("$projectDir/../../react-native/package.json") - def reactNativeVersion = new JsonSlurper().parseText(reactNativeManifest.text).version as String - // Fabric was introduced at react-native@0.68, full CMake support were introduced at react-native@0.70 - // Use Android.mk for compatibility with react-native@0.68/0.69 - reactNativeVersion.matches('(0.68.*|0.69.*)') -}() - -def codegenViewLibraryName = "ApiVideoLiveStreamView" -def codegenViewModuleName = { - // Autolink for Fabric uses codegenConfig.name in package.json since react-native@0.70 - // Use codegenViewLibraryName for compatibility with react-native@0.68/0.69 - def libraryManifestJson = new JsonSlurper().parseText(file("$projectDir/../package.json").text) - registrationCompat ? codegenViewLibraryName : libraryManifestJson.codegenConfig.name -}() - -def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') } - -if (isNewArchitectureEnabled()) { - apply plugin: "com.facebook.react" +def getExtOrIntegerDefault(prop) { + return getExtOrDefault(prop).toInteger() } -def getExtOrDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ApiVideoLivestream_" + name] +static def findNodeModulePath(baseDir, packageName) { + def basePath = baseDir.toPath().normalize() + // Node's module resolution algorithm searches up to the root directory, + // after which the base path will be null + while (basePath) { + def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName) + if (candidatePath.toFile().exists()) { + return candidatePath.toString() + } + basePath = basePath.getParent() + } + return null } -def getExtOrIntegerDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ApiVideoLivestream_" + name]).toInteger() +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" } -def supportsNamespace() { - def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') +static def supportsNamespace() { + def parsed = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') def major = parsed[0].toInteger() def minor = parsed[1].toInteger() @@ -69,6 +57,12 @@ def supportsNamespace() { return major >= 8 } +apply plugin: 'com.android.library' +if (isNewArchitectureEnabled()) { + apply plugin: 'com.facebook.react' +} +apply plugin: 'kotlin-android' + android { if (supportsNamespace()) { namespace "video.api.reactnative.livestream" @@ -87,42 +81,6 @@ android { minSdkVersion getExtOrIntegerDefault("minSdkVersion") targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() - buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null") - if (isNewArchitectureEnabled() && registrationCompat) { - def reactAndroidProject = project(':ReactAndroid') - externalNativeBuild { - ndkBuild { - arguments "APP_PLATFORM=android-21", - "APP_STL=c++_shared", - "NDK_TOOLCHAIN_VERSION=clang", - "GENERATED_SRC_DIR=$buildDir/generated/source", // for react_codegen_* in this library's codegen/jni - "PROJECT_BUILD_DIR=${appProject.buildDir}", // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk - "REACT_ANDROID_DIR=${reactAndroidProject.projectDir}", - "REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}", - "CODEGEN_MODULE_NAME=$codegenViewModuleName" - cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" - cppFlags "-std=c++17" - targets "${codegenViewModuleName}_registration" - } - } - } - } - if (isNewArchitectureEnabled() && registrationCompat) { - // We configure the NDK build only if you decide to opt-in for the New Architecture. - externalNativeBuild { - ndkBuild { - path "Android.mk" - } - } - } - buildTypes { - release { - minifyEnabled false - } - } - - lintOptions { - disable "GradleCompatible" } compileOptions { @@ -133,11 +91,7 @@ android { sourceSets { main { if (isNewArchitectureEnabled()) { - java.srcDirs += [ - "src/newarch", - // This is needed to build Kotlin project with NewArch enabled - "${project.buildDir}/generated/source/codegen/java" - ] + java.srcDirs += ["src/newarch"] } else { java.srcDirs += ["src/oldarch"] } @@ -145,12 +99,20 @@ android { } } -repositories { - mavenCentral() - google() +def reactNativePath = findNodeModulePath(projectDir, "react-native") +def codegenPath = findNodeModulePath(projectDir, "@react-native/codegen") +if (codegenPath == null) { + // Compat for 0.71 and lower (to be removed) + codegenPath = findNodeModulePath(projectDir, "react-native-codegen") } -def kotlinVersion = getExtOrDefault("kotlinVersion") +repositories { + maven { + url "${reactNativePath}/android" + } + mavenCentral() + google() +} dependencies { // For < 0.71, this will be from the local maven repo @@ -166,11 +128,3 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' } - -if (isNewArchitectureEnabled()) { - react { - jsRootDir = file("../src/") - libraryName = codegenViewLibraryName - codegenJavaPackageName = "video.api.reactnative.livestream" - } -} diff --git a/android/gradle.properties b/android/gradle.properties index 79b08e6..9e13bbe 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ -ApiVideoLivestream_kotlinVersion=1.8.0 -ApiVideoLivestream_minSdkVersion=21 -ApiVideoLivestream_targetSdkVersion=34 -ApiVideoLivestream_compileSdkVersion=34 -ApiVideoLivestream_ndkVersion=25.1.8937393 +ApiVideoLiveStream_kotlinVersion=1.8.0 +ApiVideoLiveStream_minSdkVersion=21 +ApiVideoLiveStream_targetSdkVersion=34 +ApiVideoLiveStream_compileSdkVersion=34 +ApiVideoLiveStream_ndkVersion=25.1.8937393 diff --git a/android/src/newarch/LiveStreamViewManagerSpec.kt b/android/src/newarch/LiveStreamViewManagerSpec.kt index dddb712..3034074 100644 --- a/android/src/newarch/LiveStreamViewManagerSpec.kt +++ b/android/src/newarch/LiveStreamViewManagerSpec.kt @@ -18,12 +18,4 @@ abstract class LiveStreamViewManagerSpec : SimpleViewManager(), override fun getDelegate(): ViewManagerDelegate? { return mDelegate } - - companion object { - init { - if (BuildConfig.CODEGEN_MODULE_REGISTRATION != null) { - SoLoader.loadLibrary(BuildConfig.CODEGEN_MODULE_REGISTRATION) - } - } - } }