|
| 1 | +import java.util.zip.GZIPInputStream |
| 2 | + |
| 3 | +buildscript { |
| 4 | + // Buildscript is evaluated before everything else so we can't use getExtOrDefault |
| 5 | + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : '1.9.10' |
| 6 | + |
| 7 | + repositories { |
| 8 | + google() |
| 9 | + mavenCentral() |
| 10 | + } |
| 11 | + |
| 12 | + dependencies { |
| 13 | + classpath "com.android.tools.build:gradle:7.2.2" |
| 14 | + // noinspection DifferentKotlinGradleVersion |
| 15 | + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +def isNewArchitectureEnabled() { |
| 20 | + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" |
| 21 | +} |
| 22 | + |
| 23 | +apply plugin: 'com.android.library' |
| 24 | +apply plugin: 'kotlin-android' |
| 25 | + |
| 26 | +if (isNewArchitectureEnabled()) { |
| 27 | + apply plugin: "com.facebook.react" |
| 28 | +} |
| 29 | + |
| 30 | +def safeExtGet(prop, fallback) { |
| 31 | + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
| 32 | +} |
| 33 | + |
| 34 | +android { |
| 35 | + namespace = "com.theoplayer.reactnative.adscript" |
| 36 | + compileSdkVersion safeExtGet("THEOplayerAdScript_compileSdkVersion", 35) |
| 37 | + |
| 38 | + defaultConfig { |
| 39 | + minSdkVersion safeExtGet("THEOplayerAdScript_minSdkVersion", 21) |
| 40 | + targetSdkVersion safeExtGet("THEOplayerAdScript_targetSdkVersion", 35) |
| 41 | + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() |
| 42 | + versionCode 1 |
| 43 | + versionName "1.0" |
| 44 | + } |
| 45 | + |
| 46 | + buildTypes { |
| 47 | + release { |
| 48 | + minifyEnabled false |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + lintOptions { |
| 53 | + disable "GradleCompatible" |
| 54 | + } |
| 55 | + |
| 56 | + compileOptions { |
| 57 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 58 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +repositories { |
| 63 | + mavenLocal() |
| 64 | + google() |
| 65 | + mavenCentral() |
| 66 | + // Local Maven repo |
| 67 | + maven { url("local") } |
| 68 | + maven { url "https://maven.theoplayer.com/releases" } |
| 69 | +} |
| 70 | + |
| 71 | +rootProject.allprojects { |
| 72 | + repositories { |
| 73 | + maven { url("$rootDir/../node_modules/@theoplayer/react-native-analytics-adscript/android/local") } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +// The AdScript connector requires at least THEOplayer SDK v5.11.0. |
| 78 | +def theoplayer_sdk_version = safeExtGet('THEOplayer_sdk', '[5.11.0, 10.0.0)') |
| 79 | +def kotlin_version = safeExtGet("THEOplayerAdScript_kotlinVersion", "1.9.10") |
| 80 | +def adscript_version = safeExtGet("THEOplayerAdScript_adscriptVersion", "1.0.10") |
| 81 | + |
| 82 | +dependencies { |
| 83 | + // For < 0.71, this will be from the local maven repo |
| 84 | + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin |
| 85 | + //noinspection GradleDynamicVersion |
| 86 | + implementation "com.facebook.react:react-native" |
| 87 | + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |
| 88 | + implementation 'androidx.lifecycle:lifecycle-process:2.5.1' |
| 89 | + |
| 90 | + // THEOplayer dependencies |
| 91 | + compileOnly "com.theoplayer.theoplayer-sdk-android:core:$theoplayer_sdk_version" |
| 92 | + compileOnly "com.theoplayer.theoplayer-sdk-android:integration-ads-ima:$theoplayer_sdk_version" |
| 93 | + implementation project(':react-native-theoplayer') |
| 94 | + |
| 95 | + // TEMP: replace this once the native connector has been published |
| 96 | +// implementation "com.theoplayer.android-connector:adscript:$adscript_version" |
| 97 | + implementation files("./libs/adscript.aar") |
| 98 | + def aarFileName = "AdScriptApiClient_v${adscript_version}.aar" |
| 99 | + def adScriptSdkDir = rootProject.properties['adScriptSdkDir'] |
| 100 | + if (!adScriptSdkDir) { |
| 101 | + logger.warn("⚠️ WARNING: adScriptSdkDir not set.") |
| 102 | + } else if (!rootProject.file(adScriptSdkDir).exists()) { |
| 103 | + logger.warn("⚠️ WARNING: adScriptSdkDir does not exist at: ${adScriptSdkDir}") |
| 104 | + } else { |
| 105 | + def aarFile = new File(adScriptSdkDir, aarFileName) |
| 106 | + |
| 107 | + // The AdScript aar file is typically provided as .gz, check if we still need to extract. |
| 108 | + def gzFile = new File("${aarFile}.gz") |
| 109 | + if (!aarFile.exists() && gzFile.exists()) { |
| 110 | + new FileInputStream(gzFile).withCloseable { fis -> |
| 111 | + new GZIPInputStream(fis).withCloseable { gis -> |
| 112 | + new FileOutputStream(aarFile).withCloseable { fos -> |
| 113 | + fos << gis |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + dependencies { |
| 119 | + implementation fileTree(dir: "${rootProject.file(adScriptSdkDir)}/$aarFileName", include: ['*.aar', '*.jar'], exclude: []) |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + // Align the Kotlin SDK libraries with the same version. |
| 124 | + implementation(platform("org.jetbrains.kotlin:kotlin-bom:$kotlin_version")) |
| 125 | +} |
0 commit comments