|
1 |
| -// android/build.gradle |
2 |
| - |
3 |
| -// based on: |
4 |
| -// |
5 |
| -// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle |
6 |
| -// original location: |
7 |
| -// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle |
8 |
| -// |
9 |
| -// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle |
10 |
| -// original location: |
11 |
| -// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle |
12 |
| - |
13 |
| -def DEFAULT_COMPILE_SDK_VERSION = 28 |
14 |
| -def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' |
15 |
| -def DEFAULT_MIN_SDK_VERSION = 16 |
16 |
| -def DEFAULT_TARGET_SDK_VERSION = 28 |
17 |
| - |
18 |
| -def safeExtGet(prop, fallback) { |
19 |
| - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
| 1 | +buildscript { |
| 2 | + repositories { |
| 3 | + google() |
| 4 | + mavenCentral() |
| 5 | + } |
| 6 | + |
| 7 | + dependencies { |
| 8 | + classpath 'com.android.tools.build:gradle:3.5.3' |
| 9 | + } |
20 | 10 | }
|
21 | 11 |
|
22 |
| -apply plugin: 'com.android.library' |
23 |
| -apply plugin: 'maven' |
24 |
| - |
25 |
| -buildscript { |
26 |
| - // The Android Gradle plugin is only required when opening the android folder stand-alone. |
27 |
| - // This avoids unnecessary downloads and potential conflicts when the library is included as a |
28 |
| - // module dependency in an application project. |
29 |
| - // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies |
30 |
| - if (project == rootProject) { |
31 |
| - repositories { |
32 |
| - google() |
33 |
| - jcenter() |
34 |
| - } |
35 |
| - dependencies { |
36 |
| - classpath 'com.android.tools.build:gradle:3.4.1' |
37 |
| - } |
38 |
| - } |
| 12 | +def isNewArchitectureEnabled() { |
| 13 | + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" |
39 | 14 | }
|
40 | 15 |
|
41 | 16 | apply plugin: 'com.android.library'
|
42 |
| -apply plugin: 'maven' |
43 | 17 |
|
44 |
| -android { |
45 |
| - compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) |
46 |
| - buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) |
47 |
| - defaultConfig { |
48 |
| - minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) |
49 |
| - targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) |
50 |
| - versionCode 1 |
51 |
| - versionName "1.0" |
52 |
| - } |
53 |
| - lintOptions { |
54 |
| - abortOnError false |
55 |
| - } |
56 |
| - compileOptions { |
57 |
| - sourceCompatibility = 1.8 |
58 |
| - targetCompatibility = 1.8 |
59 |
| - } |
| 18 | +if (isNewArchitectureEnabled()) { |
| 19 | + apply plugin: 'com.facebook.react' |
60 | 20 | }
|
61 | 21 |
|
62 |
| -repositories { |
63 |
| - // ref: https://www.baeldung.com/maven-local-repository |
64 |
| - mavenLocal() |
65 |
| - maven { |
66 |
| - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm |
67 |
| - url "$rootDir/../node_modules/react-native/android" |
68 |
| - } |
69 |
| - maven { |
70 |
| - // Android JSC is installed from npm |
71 |
| - url "$rootDir/../node_modules/jsc-android/dist" |
72 |
| - } |
73 |
| - google() |
74 |
| - jcenter() |
| 22 | +def getExtOrDefault(name) { |
| 23 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RnInAppUpdate_' + name] |
75 | 24 | }
|
76 | 25 |
|
77 |
| -dependencies { |
78 |
| - //noinspection GradleDynamicVersion |
79 |
| - implementation 'com.facebook.react:react-native:+' // From node_modules |
80 |
| - implementation 'com.google.android.play:core:1.7.3' |
| 26 | +def getExtOrIntegerDefault(name) { |
| 27 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RnInAppUpdate_' + name]).toInteger() |
81 | 28 | }
|
82 | 29 |
|
83 |
| -def configureReactNativePom(def pom) { |
84 |
| - def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) |
85 |
| - |
86 |
| - pom.project { |
87 |
| - name packageJson.title |
88 |
| - artifactId packageJson.name |
89 |
| - version = packageJson.version |
90 |
| - group = "com.reactlibrary.inappupdate" |
91 |
| - description packageJson.description |
92 |
| - url packageJson.repository.baseUrl |
93 |
| - |
94 |
| - licenses { |
95 |
| - license { |
96 |
| - name packageJson.license |
97 |
| - url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename |
98 |
| - distribution 'repo' |
99 |
| - } |
100 |
| - } |
101 |
| - |
102 |
| - developers { |
103 |
| - developer { |
104 |
| - id packageJson.author.username |
105 |
| - name packageJson.author.name |
106 |
| - } |
107 |
| - } |
| 30 | +android { |
| 31 | + compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') |
| 32 | + |
| 33 | + defaultConfig { |
| 34 | + minSdkVersion getExtOrIntegerDefault('minSdkVersion') |
| 35 | + targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') |
| 36 | + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() |
| 37 | + } |
| 38 | + buildTypes { |
| 39 | + release { |
| 40 | + minifyEnabled false |
108 | 41 | }
|
109 |
| -} |
| 42 | + } |
110 | 43 |
|
111 |
| -afterEvaluate { project -> |
112 |
| - // some Gradle build hooks ref: |
113 |
| - // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html |
114 |
| - task androidJavadoc(type: Javadoc) { |
115 |
| - source = android.sourceSets.main.java.srcDirs |
116 |
| - classpath += files(android.bootClasspath) |
117 |
| - classpath += files(project.getConfigurations().getByName('compile').asList()) |
118 |
| - include '**/*.java' |
119 |
| - } |
| 44 | + lintOptions { |
| 45 | + disable 'GradleCompatible' |
| 46 | + } |
120 | 47 |
|
121 |
| - task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { |
122 |
| - classifier = 'javadoc' |
123 |
| - from androidJavadoc.destinationDir |
124 |
| - } |
| 48 | + compileOptions { |
| 49 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 50 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 51 | + } |
| 52 | +} |
125 | 53 |
|
126 |
| - task androidSourcesJar(type: Jar) { |
127 |
| - classifier = 'sources' |
128 |
| - from android.sourceSets.main.java.srcDirs |
129 |
| - include '**/*.java' |
| 54 | +repositories { |
| 55 | + mavenCentral() |
| 56 | + google() |
| 57 | + |
| 58 | + def found = false |
| 59 | + def defaultDir = null |
| 60 | + def androidSourcesName = 'React Native sources' |
| 61 | + |
| 62 | + if (rootProject.ext.has('reactNativeAndroidRoot')) { |
| 63 | + defaultDir = rootProject.ext.get('reactNativeAndroidRoot') |
| 64 | + } else { |
| 65 | + defaultDir = new File( |
| 66 | + projectDir, |
| 67 | + '/../../../node_modules/react-native/android' |
| 68 | + ) |
| 69 | + } |
| 70 | + |
| 71 | + if (defaultDir.exists()) { |
| 72 | + maven { |
| 73 | + url defaultDir.toString() |
| 74 | + name androidSourcesName |
130 | 75 | }
|
131 | 76 |
|
132 |
| - android.libraryVariants.all { variant -> |
133 |
| - def name = variant.name.capitalize() |
134 |
| - def javaCompileTask = variant.javaCompileProvider.get() |
| 77 | + logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") |
| 78 | + found = true |
| 79 | + } else { |
| 80 | + def parentDir = rootProject.projectDir |
| 81 | + |
| 82 | + 1.upto(5, { |
| 83 | + if (found) return true |
| 84 | + parentDir = parentDir.parentFile |
| 85 | + |
| 86 | + def androidSourcesDir = new File( |
| 87 | + parentDir, |
| 88 | + 'node_modules/react-native' |
| 89 | + ) |
| 90 | + |
| 91 | + def androidPrebuiltBinaryDir = new File( |
| 92 | + parentDir, |
| 93 | + 'node_modules/react-native/android' |
| 94 | + ) |
| 95 | + |
| 96 | + if (androidPrebuiltBinaryDir.exists()) { |
| 97 | + maven { |
| 98 | + url androidPrebuiltBinaryDir.toString() |
| 99 | + name androidSourcesName |
| 100 | + } |
135 | 101 |
|
136 |
| - task "jar${name}"(type: Jar, dependsOn: javaCompileTask) { |
137 |
| - from javaCompileTask.destinationDir |
| 102 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") |
| 103 | + found = true |
| 104 | + } else if (androidSourcesDir.exists()) { |
| 105 | + maven { |
| 106 | + url androidSourcesDir.toString() |
| 107 | + name androidSourcesName |
138 | 108 | }
|
139 |
| - } |
140 | 109 |
|
141 |
| - artifacts { |
142 |
| - archives androidSourcesJar |
143 |
| - archives androidJavadocJar |
144 |
| - } |
| 110 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") |
| 111 | + found = true |
| 112 | + } |
| 113 | + }) |
| 114 | + } |
| 115 | + |
| 116 | + if (!found) { |
| 117 | + throw new GradleException( |
| 118 | + "${project.name}: unable to locate React Native android sources. " + |
| 119 | + "Ensure you have you installed React Native as a dependency in your project and try again." |
| 120 | + ) |
| 121 | + } |
| 122 | +} |
145 | 123 |
|
146 |
| - task installArchives(type: Upload) { |
147 |
| - configuration = configurations.archives |
148 |
| - repositories.mavenDeployer { |
149 |
| - // Deploy to react-native-event-bridge/maven, ready to publish to npm |
150 |
| - repository url: "file://${projectDir}/../android/maven" |
151 |
| - configureReactNativePom pom |
152 |
| - } |
153 |
| - } |
| 124 | + |
| 125 | +dependencies { |
| 126 | + //noinspection GradleDynamicVersion |
| 127 | + implementation "com.facebook.react:react-native:+" |
| 128 | +// implementation 'com.google.android.play:app-update:2.0.0' |
| 129 | +// From node_modules |
| 130 | + implementation 'com.google.android.play:core:1.10.3' |
| 131 | +} |
| 132 | + |
| 133 | +if (isNewArchitectureEnabled()) { |
| 134 | + react { |
| 135 | + jsRootDir = file("../src/") |
| 136 | + libraryName = "RnInAppUpdate" |
| 137 | + codegenJavaPackageName = "com.logicwind.inappupdate" |
| 138 | + } |
154 | 139 | }
|
0 commit comments