Skip to content

Commit 453bc19

Browse files
author
Chris Brody
authored
Merge pull request #135 from friederbluemle/update-project
Update android build.gradle template setup
2 parents 7678250 + 40afc0e commit 453bc19

File tree

24 files changed

+552
-408
lines changed

24 files changed

+552
-408
lines changed

templates/android.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ module.exports = platform => [{
22
name: () => `${platform}/build.gradle`,
33
content: ({ packageIdentifier }) => `// ${platform}/build.gradle
44
5-
buildscript {
6-
ext.safeExtGet = {prop, fallback ->
7-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
8-
}
9-
repositories {
10-
google()
11-
jcenter()
12-
}
5+
def safeExtGet(prop, fallback) {
6+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
7+
}
138
14-
dependencies {
15-
// Matches recent template from React Native (0.60)
16-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
17-
classpath("com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}")
9+
buildscript {
10+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
11+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
12+
// module dependency in an application project.
13+
if (project == rootProject) {
14+
repositories {
15+
google()
16+
jcenter()
17+
}
18+
dependencies {
19+
classpath 'com.android.tools.build:gradle:3.4.1'
20+
}
1821
}
1922
}
2023
@@ -44,14 +47,17 @@ android {
4447
}
4548
4649
repositories {
50+
mavenLocal()
4751
maven {
4852
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
49-
// Matches recent template from React Native 0.59 / 0.60
50-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
51-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
52-
url "$projectDir/../node_modules/react-native/android"
53+
url "$rootDir/../node_modules/react-native/android"
54+
}
55+
maven {
56+
// Android JSC is installed from npm
57+
url "$rootDir/../node_modules/jsc-android/dist"
5358
}
54-
mavenCentral()
59+
google()
60+
jcenter()
5561
}
5662
5763
dependencies {

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

+23-17
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,22 @@ sdk.dir=/Users/{username}/Library/Android/sdk
126126
"name": "react-native-integration-view-test-package/android/build.gradle",
127127
"theContent": "// android/build.gradle
128128
129-
buildscript {
130-
ext.safeExtGet = {prop, fallback ->
131-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
132-
}
133-
repositories {
134-
google()
135-
jcenter()
136-
}
129+
def safeExtGet(prop, fallback) {
130+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
131+
}
137132
138-
dependencies {
139-
// Matches recent template from React Native (0.60)
140-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
141-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
133+
buildscript {
134+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
135+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
136+
// module dependency in an application project.
137+
if (project == rootProject) {
138+
repositories {
139+
google()
140+
jcenter()
141+
}
142+
dependencies {
143+
classpath 'com.android.tools.build:gradle:3.4.1'
144+
}
142145
}
143146
}
144147
@@ -168,14 +171,17 @@ android {
168171
}
169172
170173
repositories {
174+
mavenLocal()
171175
maven {
172176
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
173-
// Matches recent template from React Native 0.59 / 0.60
174-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
175-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
176-
url \\"$projectDir/../node_modules/react-native/android\\"
177+
url \\"$rootDir/../node_modules/react-native/android\\"
178+
}
179+
maven {
180+
// Android JSC is installed from npm
181+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
177182
}
178-
mavenCentral()
183+
google()
184+
jcenter()
179185
}
180186
181187
dependencies {

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

+23-17
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,22 @@ sdk.dir=/Users/{username}/Library/Android/sdk
126126
"name": "react-native-integration-test-package/android/build.gradle",
127127
"theContent": "// android/build.gradle
128128
129-
buildscript {
130-
ext.safeExtGet = {prop, fallback ->
131-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
132-
}
133-
repositories {
134-
google()
135-
jcenter()
136-
}
129+
def safeExtGet(prop, fallback) {
130+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
131+
}
137132
138-
dependencies {
139-
// Matches recent template from React Native (0.60)
140-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
141-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
133+
buildscript {
134+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
135+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
136+
// module dependency in an application project.
137+
if (project == rootProject) {
138+
repositories {
139+
google()
140+
jcenter()
141+
}
142+
dependencies {
143+
classpath 'com.android.tools.build:gradle:3.4.1'
144+
}
142145
}
143146
}
144147
@@ -168,14 +171,17 @@ android {
168171
}
169172
170173
repositories {
174+
mavenLocal()
171175
maven {
172176
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
173-
// Matches recent template from React Native 0.59 / 0.60
174-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
175-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
176-
url \\"$projectDir/../node_modules/react-native/android\\"
177+
url \\"$rootDir/../node_modules/react-native/android\\"
178+
}
179+
maven {
180+
// Android JSC is installed from npm
181+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
177182
}
178-
mavenCentral()
183+
google()
184+
jcenter()
179185
}
180186
181187
dependencies {

tests/with-injection/create/view/with-defaults/__snapshots__/create-view-with-defaults.test.js.snap

+23-17
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,22 @@ content:
201201
--------
202202
// android/build.gradle
203203
204-
buildscript {
205-
ext.safeExtGet = {prop, fallback ->
206-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
207-
}
208-
repositories {
209-
google()
210-
jcenter()
211-
}
204+
def safeExtGet(prop, fallback) {
205+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
206+
}
212207
213-
dependencies {
214-
// Matches recent template from React Native (0.60)
215-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
216-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
208+
buildscript {
209+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
210+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
211+
// module dependency in an application project.
212+
if (project == rootProject) {
213+
repositories {
214+
google()
215+
jcenter()
216+
}
217+
dependencies {
218+
classpath 'com.android.tools.build:gradle:3.4.1'
219+
}
217220
}
218221
}
219222
@@ -243,14 +246,17 @@ android {
243246
}
244247
245248
repositories {
249+
mavenLocal()
246250
maven {
247251
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
248-
// Matches recent template from React Native 0.59 / 0.60
249-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
250-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
251-
url \\"$projectDir/../node_modules/react-native/android\\"
252+
url \\"$rootDir/../node_modules/react-native/android\\"
253+
}
254+
maven {
255+
// Android JSC is installed from npm
256+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
252257
}
253-
mavenCentral()
258+
google()
259+
jcenter()
254260
}
255261
256262
dependencies {

tests/with-injection/create/view/with-example/with-defaults/__snapshots__/create-view-with-example-with-defaults.test.js.snap

+23-17
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,22 @@ content:
206206
--------
207207
// android/build.gradle
208208
209-
buildscript {
210-
ext.safeExtGet = {prop, fallback ->
211-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
212-
}
213-
repositories {
214-
google()
215-
jcenter()
216-
}
209+
def safeExtGet(prop, fallback) {
210+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
211+
}
217212
218-
dependencies {
219-
// Matches recent template from React Native (0.60)
220-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
221-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
213+
buildscript {
214+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
215+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
216+
// module dependency in an application project.
217+
if (project == rootProject) {
218+
repositories {
219+
google()
220+
jcenter()
221+
}
222+
dependencies {
223+
classpath 'com.android.tools.build:gradle:3.4.1'
224+
}
222225
}
223226
}
224227
@@ -248,14 +251,17 @@ android {
248251
}
249252
250253
repositories {
254+
mavenLocal()
251255
maven {
252256
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
253-
// Matches recent template from React Native 0.59 / 0.60
254-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
255-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
256-
url \\"$projectDir/../node_modules/react-native/android\\"
257+
url \\"$rootDir/../node_modules/react-native/android\\"
258+
}
259+
maven {
260+
// Android JSC is installed from npm
261+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
257262
}
258-
mavenCentral()
263+
google()
264+
jcenter()
259265
}
260266
261267
dependencies {

tests/with-injection/create/view/with-example/with-options/__snapshots__/create-view-with-example-with-options.test.js.snap

+23-17
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,22 @@ content:
206206
--------
207207
// android/build.gradle
208208
209-
buildscript {
210-
ext.safeExtGet = {prop, fallback ->
211-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
212-
}
213-
repositories {
214-
google()
215-
jcenter()
216-
}
209+
def safeExtGet(prop, fallback) {
210+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
211+
}
217212
218-
dependencies {
219-
// Matches recent template from React Native (0.60)
220-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
221-
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
213+
buildscript {
214+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
215+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
216+
// module dependency in an application project.
217+
if (project == rootProject) {
218+
repositories {
219+
google()
220+
jcenter()
221+
}
222+
dependencies {
223+
classpath 'com.android.tools.build:gradle:3.4.1'
224+
}
222225
}
223226
}
224227
@@ -248,14 +251,17 @@ android {
248251
}
249252
250253
repositories {
254+
mavenLocal()
251255
maven {
252256
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
253-
// Matches recent template from React Native 0.59 / 0.60
254-
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
255-
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
256-
url \\"$projectDir/../node_modules/react-native/android\\"
257+
url \\"$rootDir/../node_modules/react-native/android\\"
258+
}
259+
maven {
260+
// Android JSC is installed from npm
261+
url \\"$rootDir/../node_modules/jsc-android/dist\\"
257262
}
258-
mavenCentral()
263+
google()
264+
jcenter()
259265
}
260266
261267
dependencies {

0 commit comments

Comments
 (0)