|
1 | | -apply plugin: "com.android.library" |
2 | | - |
3 | | -def isNewArchitectureEnabled() { |
4 | | - // To opt-in for the New Architecture, you can either: |
5 | | - // - Set `newArchEnabled` to true inside the `gradle.properties` file |
6 | | - // - Invoke gradle with `-newArchEnabled=true` |
7 | | - // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` |
8 | | - return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" |
9 | | -} |
| 1 | +import groovy.json.JsonSlurper |
10 | 2 |
|
11 | | -def IS_NEW_ARCHITECTURE_ENABLED = isNewArchitectureEnabled() |
| 3 | +apply plugin: "com.android.library" |
12 | 4 |
|
13 | | -if (IS_NEW_ARCHITECTURE_ENABLED) { |
14 | | - apply plugin: "com.facebook.react" |
| 5 | +def safeExtGet(prop, fallback) { |
| 6 | + return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
15 | 7 | } |
16 | 8 |
|
17 | 9 | def DEFAULT_COMPILE_SDK_VERSION = 26 |
18 | | -def DEFAULT_BUILD_TOOLS_VERSION = "26.0.3" |
19 | 10 | def DEFAULT_TARGET_SDK_VERSION = 26 |
20 | 11 | def DEFAULT_MIN_SDK_VERSION = 16 |
21 | 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 | + |
22 | 58 | android { |
23 | | - namespace "com.microsoft.codepush.react" |
| 59 | + if (project.android.hasProperty("namespace")) { |
| 60 | + namespace "com.microsoft.codepush.react" |
| 61 | + } |
24 | 62 |
|
25 | | - compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION |
26 | | - buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION |
| 63 | + compileSdkVersion safeExtGet("compileSdkVersion", DEFAULT_COMPILE_SDK_VERSION) |
27 | 64 |
|
28 | 65 | defaultConfig { |
29 | | - minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION |
30 | | - targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION |
| 66 | + minSdkVersion safeExtGet("minSdkVersion", DEFAULT_MIN_SDK_VERSION) |
| 67 | + targetSdkVersion safeExtGet("targetSdkVersion", DEFAULT_TARGET_SDK_VERSION) |
31 | 68 | versionCode 1 |
32 | 69 | versionName "1.0" |
33 | | - buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", IS_NEW_ARCHITECTURE_ENABLED.toString() |
| 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 |
34 | 82 | } |
35 | 83 |
|
36 | 84 | lintOptions { |
37 | 85 | abortOnError false |
38 | 86 | } |
| 87 | +} |
39 | 88 |
|
40 | | - defaultConfig { |
41 | | - consumerProguardFiles 'proguard-rules.pro' |
42 | | - } |
| 89 | +repositories { |
| 90 | + google() |
| 91 | + mavenCentral() |
| 92 | + mavenLocal() |
43 | 93 | } |
44 | 94 |
|
45 | 95 | dependencies { |
46 | | - implementation "com.facebook.react:react-native:+" |
47 | | - implementation 'com.nimbusds:nimbus-jose-jwt:9.37.3' |
| 96 | + implementation(reactNativeDependency) |
| 97 | + implementation "com.nimbusds:nimbus-jose-jwt:9.37.3" |
48 | 98 | } |
0 commit comments