Skip to content

Update android build.gradle template setup #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions templates/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ module.exports = platform => [{
name: () => `${platform}/build.gradle`,
content: ({ packageIdentifier }) => `// ${platform}/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

dependencies {
// Matches recent template from React Native (0.60)
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
classpath("com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}")
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole repositories block with google() and jcenter() entries seems to be duplicated now, considering that there is a bigger repositories block in some code below. Or am I missing something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not duplicated. One is for the buildscripts, the other for the dependencies. You can read more about this here: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies

google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

Expand Down Expand Up @@ -44,14 +47,17 @@ android {
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches recent template from React Native 0.59 / 0.60
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the comments here?

// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
url "$projectDir/../node_modules/react-native/android"
url "$rootDir/../node_modules/react-native/android"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional comment would be nice for people like me who evidently don't understand Gradle and Maven so well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are taken from the official RN template. I did not make any modification, since this is the file that will end up in an end user's generated project. I did not see any comments or reasons for this to be different here. If additional documentation/comments are necessary I'd suggest we go to the source (react-native) first to update it there.

}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
mavenCentral()
google()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is some reordering. Explanation would be helpful for people like me.

jcenter()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,22 @@ sdk.dir=/Users/{username}/Library/Android/sdk
"name": "react-native-integration-view-test-package/android/build.gradle",
"theContent": "// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

dependencies {
// Matches recent template from React Native (0.60)
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

Expand Down Expand Up @@ -168,14 +171,17 @@ android {
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
url \\"$projectDir/../node_modules/react-native/android\\"
url \\"$rootDir/../node_modules/react-native/android\\"
}
maven {
// Android JSC is installed from npm
url \\"$rootDir/../node_modules/jsc-android/dist\\"
}
mavenCentral()
google()
jcenter()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,22 @@ sdk.dir=/Users/{username}/Library/Android/sdk
"name": "react-native-integration-test-package/android/build.gradle",
"theContent": "// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

dependencies {
// Matches recent template from React Native (0.60)
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

Expand Down Expand Up @@ -168,14 +171,17 @@ android {
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
url \\"$projectDir/../node_modules/react-native/android\\"
url \\"$rootDir/../node_modules/react-native/android\\"
}
maven {
// Android JSC is installed from npm
url \\"$rootDir/../node_modules/jsc-android/dist\\"
}
mavenCentral()
google()
jcenter()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,22 @@ content:
--------
// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

dependencies {
// Matches recent template from React Native (0.60)
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

Expand Down Expand Up @@ -243,14 +246,17 @@ android {
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
url \\"$projectDir/../node_modules/react-native/android\\"
url \\"$rootDir/../node_modules/react-native/android\\"
}
maven {
// Android JSC is installed from npm
url \\"$rootDir/../node_modules/jsc-android/dist\\"
}
mavenCentral()
google()
jcenter()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@ content:
--------
// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

dependencies {
// Matches recent template from React Native (0.60)
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

Expand Down Expand Up @@ -248,14 +251,17 @@ android {
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
url \\"$projectDir/../node_modules/react-native/android\\"
url \\"$rootDir/../node_modules/react-native/android\\"
}
maven {
// Android JSC is installed from npm
url \\"$rootDir/../node_modules/jsc-android/dist\\"
}
mavenCentral()
google()
jcenter()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@ content:
--------
// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

dependencies {
// Matches recent template from React Native (0.60)
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L16
classpath(\\"com.android.tools.build:gradle:\${safeExtGet('gradlePluginVersion', '3.4.1')}\\")
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

Expand Down Expand Up @@ -248,14 +251,17 @@ android {
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L30
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L28
url \\"$projectDir/../node_modules/react-native/android\\"
url \\"$rootDir/../node_modules/react-native/android\\"
}
maven {
// Android JSC is installed from npm
url \\"$rootDir/../node_modules/jsc-android/dist\\"
}
mavenCentral()
google()
jcenter()
}

dependencies {
Expand Down
Loading