Skip to content

Commit 88df273

Browse files
Update android build.gradle template setup
This wraps the buildscripts dependencies in a conditional. More information here: facebook/react-native#25569 (comment)
1 parent 22100b5 commit 88df273

File tree

24 files changed

+864
-768
lines changed

24 files changed

+864
-768
lines changed

templates/android.js

+36-32
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
module.exports = platform => [{
22
name: () => `${platform}/build.gradle`,
3-
content: ({ packageIdentifier }) => `buildscript {
4-
ext.safeExtGet = {prop, fallback ->
5-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
6-
}
7-
repositories {
8-
google()
9-
jcenter()
10-
}
3+
content: ({ packageIdentifier }) => `def safeExtGet(prop, fallback) {
4+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5+
}
116
12-
dependencies {
13-
// Matches recent template from React Native (0.60)
14-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
15-
classpath("com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}")
7+
buildscript {
8+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
9+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
10+
// module dependency in an application project.
11+
if (project == rootProject) {
12+
repositories {
13+
google()
14+
jcenter()
15+
}
16+
dependencies {
17+
classpath 'com.android.tools.build:gradle:3.4.1'
18+
}
1619
}
1720
}
1821
@@ -28,33 +31,36 @@ def DEFAULT_MIN_SDK_VERSION = 16
2831
def DEFAULT_TARGET_SDK_VERSION = 28
2932
3033
android {
31-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
32-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
33-
34-
defaultConfig {
35-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
36-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
37-
versionCode 1
38-
versionName "1.0"
39-
}
40-
lintOptions {
41-
abortOnError false
42-
}
34+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
35+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
36+
defaultConfig {
37+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
38+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
39+
versionCode 1
40+
versionName "1.0"
41+
}
42+
lintOptions {
43+
abortOnError false
44+
}
4345
}
4446
4547
repositories {
48+
mavenLocal()
4649
maven {
4750
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
48-
// Matches recent template from React Native 0.59 / 0.60
49-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
50-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
51-
url "$projectDir/../node_modules/react-native/android"
51+
url "$rootDir/../node_modules/react-native/android"
52+
}
53+
maven {
54+
// Android JSC is installed from npm
55+
url "$rootDir/../node_modules/jsc-android/dist"
5256
}
53-
mavenCentral()
57+
google()
58+
jcenter()
5459
}
5560
5661
dependencies {
57-
implementation "com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}"
62+
//noinspection GradleDynamicVersion
63+
implementation 'com.facebook.react:react-native:+' // From node_modules
5864
}
5965
6066
def configureReactNativePom(def pom) {
@@ -86,7 +92,6 @@ def configureReactNativePom(def pom) {
8692
}
8793
8894
afterEvaluate { project ->
89-
9095
task androidJavadoc(type: Javadoc) {
9196
source = android.sourceSets.main.java.srcDirs
9297
classpath += files(android.bootClasspath)
@@ -122,7 +127,6 @@ afterEvaluate { project ->
122127
repositories.mavenDeployer {
123128
// Deploy to react-native-event-bridge/maven, ready to publish to npm
124129
repository url: "file://\${projectDir}/../android/maven"
125-
126130
configureReactNativePom pom
127131
}
128132
}

tests/integration/cli/create/view/__snapshots__/cli-create-with-view.test.js.snap

+36-32
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,22 @@ sdk.dir=/Users/{username}/Library/Android/sdk
124124
},
125125
Object {
126126
"name": "react-native-integration-view-test-package/android/build.gradle",
127-
"theContent": "buildscript {
128-
ext.safeExtGet = {prop, fallback ->
129-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
130-
}
131-
repositories {
132-
google()
133-
jcenter()
134-
}
127+
"theContent": "def safeExtGet(prop, fallback) {
128+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
129+
}
135130
136-
dependencies {
137-
// Matches recent template from React Native (0.60)
138-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
139-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
131+
buildscript {
132+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
133+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
134+
// module dependency in an application project.
135+
if (project == rootProject) {
136+
repositories {
137+
google()
138+
jcenter()
139+
}
140+
dependencies {
141+
classpath 'com.android.tools.build:gradle:3.5.0'
142+
}
140143
}
141144
}
142145
@@ -152,33 +155,36 @@ def DEFAULT_MIN_SDK_VERSION = 16
152155
def DEFAULT_TARGET_SDK_VERSION = 28
153156
154157
android {
155-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
156-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
157-
158-
defaultConfig {
159-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
160-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
161-
versionCode 1
162-
versionName \\"1.0\\"
163-
}
164-
lintOptions {
165-
abortOnError false
166-
}
158+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
159+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
160+
defaultConfig {
161+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
162+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
163+
versionCode 1
164+
versionName \\"1.0\\"
165+
}
166+
lintOptions {
167+
abortOnError false
168+
}
167169
}
168170
169171
repositories {
172+
mavenLocal()
170173
maven {
171174
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
172-
// Matches recent template from React Native 0.59 / 0.60
173-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
174-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
175-
url \\"$projectDir/../node_modules/react-native/android\\"
175+
url \\"$rootDir/../node_modules/react-native/android\\"
176+
}
177+
maven {
178+
// Android JSC is installed from npm
179+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
176180
}
177-
mavenCentral()
181+
google()
182+
jcenter()
178183
}
179184
180185
dependencies {
181-
implementation \\"com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}\\"
186+
//noinspection GradleDynamicVersion
187+
implementation 'com.facebook.react:react-native:+' // From node_modules
182188
}
183189
184190
def configureReactNativePom(def pom) {
@@ -210,7 +216,6 @@ def configureReactNativePom(def pom) {
210216
}
211217
212218
afterEvaluate { project ->
213-
214219
task androidJavadoc(type: Javadoc) {
215220
source = android.sourceSets.main.java.srcDirs
216221
classpath += files(android.bootClasspath)
@@ -246,7 +251,6 @@ afterEvaluate { project ->
246251
repositories.mavenDeployer {
247252
// Deploy to react-native-event-bridge/maven, ready to publish to npm
248253
repository url: \\"file://\${projectDir}/../android/maven\\"
249-
250254
configureReactNativePom pom
251255
}
252256
}

tests/integration/cli/create/with-defaults/__snapshots__/cli-create-with-defaults.test.js.snap

+36-32
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,22 @@ sdk.dir=/Users/{username}/Library/Android/sdk
124124
},
125125
Object {
126126
"name": "react-native-integration-test-package/android/build.gradle",
127-
"theContent": "buildscript {
128-
ext.safeExtGet = {prop, fallback ->
129-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
130-
}
131-
repositories {
132-
google()
133-
jcenter()
134-
}
127+
"theContent": "def safeExtGet(prop, fallback) {
128+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
129+
}
135130
136-
dependencies {
137-
// Matches recent template from React Native (0.60)
138-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
139-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
131+
buildscript {
132+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
133+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
134+
// module dependency in an application project.
135+
if (project == rootProject) {
136+
repositories {
137+
google()
138+
jcenter()
139+
}
140+
dependencies {
141+
classpath 'com.android.tools.build:gradle:3.5.0'
142+
}
140143
}
141144
}
142145
@@ -152,33 +155,36 @@ def DEFAULT_MIN_SDK_VERSION = 16
152155
def DEFAULT_TARGET_SDK_VERSION = 28
153156
154157
android {
155-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
156-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
157-
158-
defaultConfig {
159-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
160-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
161-
versionCode 1
162-
versionName \\"1.0\\"
163-
}
164-
lintOptions {
165-
abortOnError false
166-
}
158+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
159+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
160+
defaultConfig {
161+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
162+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
163+
versionCode 1
164+
versionName \\"1.0\\"
165+
}
166+
lintOptions {
167+
abortOnError false
168+
}
167169
}
168170
169171
repositories {
172+
mavenLocal()
170173
maven {
171174
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
172-
// Matches recent template from React Native 0.59 / 0.60
173-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
174-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
175-
url \\"$projectDir/../node_modules/react-native/android\\"
175+
url \\"$rootDir/../node_modules/react-native/android\\"
176+
}
177+
maven {
178+
// Android JSC is installed from npm
179+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
176180
}
177-
mavenCentral()
181+
google()
182+
jcenter()
178183
}
179184
180185
dependencies {
181-
implementation \\"com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}\\"
186+
//noinspection GradleDynamicVersion
187+
implementation 'com.facebook.react:react-native:+' // From node_modules
182188
}
183189
184190
def configureReactNativePom(def pom) {
@@ -210,7 +216,6 @@ def configureReactNativePom(def pom) {
210216
}
211217
212218
afterEvaluate { project ->
213-
214219
task androidJavadoc(type: Javadoc) {
215220
source = android.sourceSets.main.java.srcDirs
216221
classpath += files(android.bootClasspath)
@@ -246,7 +251,6 @@ afterEvaluate { project ->
246251
repositories.mavenDeployer {
247252
// Deploy to react-native-event-bridge/maven, ready to publish to npm
248253
repository url: \\"file://\${projectDir}/../android/maven\\"
249-
250254
configureReactNativePom pom
251255
}
252256
}

0 commit comments

Comments
 (0)