|
| 1 | +import groovy.json.JsonSlurper |
| 2 | + |
| 3 | +apply plugin: "com.android.library" |
| 4 | + |
| 5 | +def safeExtGet(prop, fallback) { |
| 6 | + return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
| 7 | +} |
| 8 | + |
| 9 | +def DEFAULT_COMPILE_SDK_VERSION = 26 |
| 10 | +def DEFAULT_TARGET_SDK_VERSION = 26 |
| 11 | +def DEFAULT_MIN_SDK_VERSION = 16 |
| 12 | + |
| 13 | +def findReactNativePackageJson() { |
| 14 | + File currentDir = projectDir |
| 15 | + |
| 16 | + while (currentDir != null) { |
| 17 | + File packageJson = new File(currentDir, "node_modules/react-native/package.json") |
| 18 | + if (packageJson.exists()) { |
| 19 | + return packageJson |
| 20 | + } |
| 21 | + |
| 22 | + currentDir = currentDir.parentFile |
| 23 | + } |
| 24 | + |
| 25 | + return null |
| 26 | +} |
| 27 | + |
| 28 | +def getReactNativeVersion() { |
| 29 | + File packageJson = findReactNativePackageJson() |
| 30 | + if (packageJson == null) { |
| 31 | + return null |
| 32 | + } |
| 33 | + |
| 34 | + def version = new JsonSlurper().parseText(packageJson.text).version |
| 35 | + return version.tokenize("-")[0] |
| 36 | +} |
| 37 | + |
| 38 | +def getReactNativeMinorVersion() { |
| 39 | + def reactNativeVersion = getReactNativeVersion() |
| 40 | + if (reactNativeVersion == null) { |
| 41 | + return null |
| 42 | + } |
| 43 | + |
| 44 | + def versionParts = reactNativeVersion.tokenize(".") |
| 45 | + if (versionParts.size() < 2) { |
| 46 | + return null |
| 47 | + } |
| 48 | + |
| 49 | + return versionParts[1].toInteger() |
| 50 | +} |
| 51 | + |
| 52 | +def reactNativeVersion = getReactNativeVersion() |
| 53 | +def reactNativeMinorVersion = getReactNativeMinorVersion() |
| 54 | +def reactNativeDependency = reactNativeMinorVersion != null && reactNativeMinorVersion < 71 |
| 55 | + ? "com.facebook.react:react-native:${reactNativeVersion ?: '+'}" |
| 56 | + : "com.facebook.react:react-android:${reactNativeVersion ?: '+'}" |
| 57 | + |
| 58 | +android { |
| 59 | + if (project.android.hasProperty("namespace")) { |
| 60 | + namespace "com.microsoft.codepush.react" |
| 61 | + } |
| 62 | + |
| 63 | + compileSdkVersion safeExtGet("compileSdkVersion", DEFAULT_COMPILE_SDK_VERSION) |
| 64 | + |
| 65 | + defaultConfig { |
| 66 | + minSdkVersion safeExtGet("minSdkVersion", DEFAULT_MIN_SDK_VERSION) |
| 67 | + targetSdkVersion safeExtGet("targetSdkVersion", DEFAULT_TARGET_SDK_VERSION) |
| 68 | + versionCode 1 |
| 69 | + versionName "1.0" |
| 70 | + consumerProguardFiles "../proguard-rules.pro" |
| 71 | + } |
| 72 | + |
| 73 | + sourceSets { |
| 74 | + main { |
| 75 | + java.srcDirs = ["../src/main/java"] |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + compileOptions { |
| 80 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 81 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 82 | + } |
| 83 | + |
| 84 | + lintOptions { |
| 85 | + abortOnError false |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +repositories { |
| 90 | + google() |
| 91 | + mavenCentral() |
| 92 | + mavenLocal() |
| 93 | +} |
| 94 | + |
| 95 | +dependencies { |
| 96 | + implementation(reactNativeDependency) |
| 97 | + implementation "com.nimbusds:nimbus-jose-jwt:9.37.3" |
| 98 | +} |
0 commit comments