6189080c9a
* feat(android): add error handling for Kotlin version mismatch * fix: lint error * refactor: use variables from gradle file * chore: downgrade required Kotlin version * refactor: check Kotlin version * refactor: kotlin variables in build.gradle * refactor: kotlin variables in build.gradle * chore(doc): update document * chore: add dependency to build.gradle for a specific version of react-native * fix: remove additional dependency
305 lines
10 KiB
Groovy
305 lines
10 KiB
Groovy
import com.android.Version
|
|
|
|
apply plugin: 'com.android.library'
|
|
apply plugin: 'kotlin-android'
|
|
|
|
buildscript {
|
|
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNVideo_kotlinVersion']
|
|
def requiredKotlinVersion = project.properties['RNVideo_kotlinVersion']
|
|
|
|
def isVersionAtLeast = { version, requiredVersion ->
|
|
def (v1, v2) = [version, requiredVersion].collect { it.tokenize('.')*.toInteger() }
|
|
for (int i = 0; i < Math.max(v1.size(), v2.size()); i++) {
|
|
int val1 = i < v1.size() ? v1[i] : 0
|
|
int val2 = i < v2.size() ? v2[i] : 0
|
|
if (val1 < val2) {
|
|
return false
|
|
} else if (val1 > val2) {
|
|
return true
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
|
|
}
|
|
|
|
ext {
|
|
if (!isVersionAtLeast(kotlin_version, requiredKotlinVersion)) {
|
|
throw new GradleException("Kotlin version mismatch: Project is using Kotlin version $kotlin_version, but it must be at least $requiredKotlinVersion. Please update the Kotlin version.")
|
|
} else {
|
|
println("Kotlin version is correct: $kotlin_version")
|
|
}
|
|
}
|
|
}
|
|
|
|
// This looks funny but it's necessary to keep backwards compatibility (:
|
|
def safeExtGet(prop) {
|
|
return rootProject.ext.has(prop) ?
|
|
rootProject.ext.get(prop) : rootProject.ext.has("RNVideo_" + prop) ?
|
|
rootProject.ext.get("RNVideo_" + prop) : project.properties["RNVideo_" + prop]
|
|
}
|
|
|
|
def isNewArchitectureEnabled() {
|
|
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
}
|
|
|
|
def supportsNamespace() {
|
|
def parsed = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
def major = parsed[0].toInteger()
|
|
def minor = parsed[1].toInteger()
|
|
|
|
// Namespace support was added in 7.3.0
|
|
if (major == 7 && minor >= 3) {
|
|
return true
|
|
}
|
|
|
|
return major >= 8
|
|
}
|
|
|
|
def ExoplayerDependenciesList = [
|
|
"useExoplayerIMA",
|
|
"useExoplayerSmoothStreaming",
|
|
"useExoplayerDash",
|
|
"useExoplayerHls",
|
|
"useExoplayerRtsp",
|
|
]
|
|
def media3_buildFromSource = safeExtGet('buildFromMedia3Source').toBoolean() ?: false
|
|
|
|
def ExoplayerDependencies = ExoplayerDependenciesList.collectEntries { property ->
|
|
[(property): safeExtGet(property)?.toBoolean() ?: false]
|
|
}
|
|
|
|
ExoplayerDependenciesList.each { propertyName ->
|
|
def propertyValue = ExoplayerDependencies[propertyName]
|
|
println "$propertyName: $propertyValue"
|
|
}
|
|
println "buildFromSource: $media3_buildFromSource"
|
|
|
|
// This string is used to define build path.
|
|
// As react native build output directory is react-native path of the module.
|
|
// We need to force a new path on each configuration change.
|
|
// If you add a new build parameter, please add the new value in this string
|
|
def configStringPath = ExoplayerDependencies
|
|
.collect { property, value -> property + value}
|
|
.join('')
|
|
.concat("buildFromSource:$media3_buildFromSource")
|
|
.md5()
|
|
|
|
if (isNewArchitectureEnabled()) {
|
|
apply plugin: "com.facebook.react"
|
|
}
|
|
|
|
android {
|
|
if (supportsNamespace()) {
|
|
namespace 'com.brentvatne.react'
|
|
|
|
sourceSets {
|
|
main {
|
|
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
}
|
|
}
|
|
}
|
|
|
|
compileSdkVersion safeExtGet('compileSdkVersion')
|
|
buildToolsVersion safeExtGet('buildToolsVersion')
|
|
|
|
def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
compileOptions {
|
|
sourceCompatibility JavaVersion.VERSION_11
|
|
targetCompatibility JavaVersion.VERSION_11
|
|
}
|
|
|
|
kotlinOptions {
|
|
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
}
|
|
}
|
|
|
|
defaultConfig {
|
|
minSdkVersion safeExtGet('minSdkVersion')
|
|
targetSdkVersion safeExtGet('targetSdkVersion')
|
|
versionCode 1
|
|
versionName "1.0"
|
|
|
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
buildConfigField "boolean", "USE_EXOPLAYER_IMA", ExoplayerDependencies["useExoplayerIMA"].toString()
|
|
buildConfigField "boolean", "USE_EXOPLAYER_SMOOTH_STREAMING", ExoplayerDependencies["useExoplayerSmoothStreaming"].toString()
|
|
buildConfigField "boolean", "USE_EXOPLAYER_DASH", ExoplayerDependencies["useExoplayerDash"].toString()
|
|
buildConfigField "boolean", "USE_EXOPLAYER_HLS", ExoplayerDependencies["useExoplayerHls"].toString()
|
|
buildConfigField "boolean", "USE_EXOPLAYER_RTSP", ExoplayerDependencies["useExoplayerRtsp"].toString()
|
|
|
|
ndk {
|
|
abiFilters(*reactNativeArchitectures())
|
|
}
|
|
}
|
|
|
|
buildFeatures {
|
|
buildConfig true
|
|
}
|
|
|
|
packagingOptions {
|
|
exclude "**/libreact_render*.so"
|
|
}
|
|
|
|
buildDir 'buildOutput_' + configStringPath
|
|
|
|
sourceSets {
|
|
main {
|
|
java {
|
|
if (ExoplayerDependencies["useExoplayerIMA"]) {
|
|
exclude 'com/google/ads/interactivemedia/v3/api'
|
|
exclude 'androidx/media3/exoplayer/ima'
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerSmoothStreaming"]) {
|
|
exclude 'androidx/media3/exoplayer/smoothstreaming'
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerDash"]) {
|
|
exclude 'androidx/media3/exoplayer/dash'
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerHls"]) {
|
|
exclude 'androidx/media3/exoplayer/hls'
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerRtsp"]) {
|
|
exclude 'androidx/media3/exoplayer/rtsp'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sourceSets.main {
|
|
java {
|
|
if (isNewArchitectureEnabled()) {
|
|
srcDirs += [
|
|
"src/fabric/java",
|
|
"${project.buildDir}/generated/source/codegen/java"
|
|
]
|
|
} else {
|
|
srcDirs += [
|
|
"src/oldarch/java"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def reactNativeArchitectures() {
|
|
def value = project.getProperties().get("reactNativeArchitectures")
|
|
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
}
|
|
|
|
repositories {
|
|
google()
|
|
maven {
|
|
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
url "$rootDir/../node_modules/react-native/android"
|
|
}
|
|
mavenCentral()
|
|
}
|
|
|
|
def media3_version = safeExtGet('media3Version')
|
|
def androidxCore_version = safeExtGet('androidxCoreVersion')
|
|
def androidxActivity_version = safeExtGet('androidxActivityVersion')
|
|
|
|
dependencies {
|
|
// For < 0.71, this will be from the local maven repo
|
|
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
//noinspection GradleDynamicVersion
|
|
implementation "com.facebook.react:react-native:+"
|
|
|
|
implementation "androidx.core:core:$androidxCore_version"
|
|
implementation "androidx.activity:activity-ktx:$androidxActivity_version"
|
|
|
|
// For media playback using ExoPlayer
|
|
if (media3_buildFromSource) {
|
|
implementation(project(":media-lib-exoplayer"))
|
|
} else {
|
|
implementation "androidx.media3:media3-exoplayer:$media3_version"
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerSmoothStreaming"]) {
|
|
// For Smooth Streaming playback support with ExoPlayer
|
|
if (media3_buildFromSource) {
|
|
implementation(project(":media-lib-exoplayer-smoothstreaming"))
|
|
} else {
|
|
implementation "androidx.media3:media3-exoplayer-smoothstreaming:$media3_version"
|
|
}
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerDash"]) {
|
|
// For DASH playback support with ExoPlayer
|
|
if (media3_buildFromSource) {
|
|
implementation(project(":media-lib-exoplayer-dash"))
|
|
} else {
|
|
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
|
|
}
|
|
}
|
|
|
|
if (ExoplayerDependencies["useExoplayerHls"]) {
|
|
// For HLS playback support with ExoPlayer
|
|
if (media3_buildFromSource) {
|
|
implementation(project(":media-lib-exoplayer-hls"))
|
|
} else {
|
|
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
|
|
}
|
|
}
|
|
|
|
// For RTSP playback support with ExoPlayer
|
|
if (ExoplayerDependencies["useExoplayerRtsp"]) {
|
|
if (media3_buildFromSource) {
|
|
implementation(project(":media-lib-exoplayer-rtsp"))
|
|
} else {
|
|
implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
|
|
}
|
|
}
|
|
|
|
// For ad insertion using the Interactive Media Ads SDK with ExoPlayer
|
|
if (ExoplayerDependencies["useExoplayerIMA"]) {
|
|
if (media3_buildFromSource) {
|
|
implementation(project(":media-lib-exoplayer-ima"))
|
|
} else {
|
|
implementation "androidx.media3:media3-exoplayer-ima:$media3_version"
|
|
}
|
|
}
|
|
|
|
if (media3_buildFromSource) {
|
|
// For loading data using the OkHttp network stack
|
|
implementation(project(":media-lib-datasource-okhttp"))
|
|
|
|
// For building media playback UIs
|
|
implementation(project(":media-lib-ui"))
|
|
|
|
// For exposing and controlling media sessions
|
|
implementation(project(":media-lib-session"))
|
|
|
|
// Common functionality for loading data
|
|
implementation(project(":media-lib-datasource"))
|
|
|
|
// Common functionality used across multiple media libraries
|
|
implementation(project(":media-lib-common"))
|
|
} else {
|
|
// For loading data using the OkHttp network stack
|
|
implementation "androidx.media3:media3-datasource-okhttp:$media3_version"
|
|
|
|
// For building media playback UIs
|
|
implementation "androidx.media3:media3-ui:$media3_version"
|
|
|
|
// For exposing and controlling media sessions
|
|
implementation "androidx.media3:media3-session:$media3_version"
|
|
|
|
// Common functionality for loading data
|
|
implementation "androidx.media3:media3-datasource:$media3_version"
|
|
|
|
// Common functionality used across multiple media libraries
|
|
implementation "androidx.media3:media3-common:$media3_version"
|
|
}
|
|
} |