Skip to content

cleanup generated android/build.gradle artifact #138

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 5 commits into from
Sep 18, 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
36 changes: 20 additions & 16 deletions templates/android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = platform => [{
name: () => `${platform}/build.gradle`,
content: ({ packageIdentifier }) => `buildscript {
content: ({ packageIdentifier }) => `// ${platform}/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
Expand Down Expand Up @@ -28,18 +30,17 @@ def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

repositories {
Expand All @@ -54,7 +55,10 @@ repositories {
}

dependencies {
implementation "com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}"
// ref:
// https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.facebook.react:react-native:+' // from node_modules

Copy link
Contributor

@friederbluemle friederbluemle Sep 18, 2019

Choose a reason for hiding this comment

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

This comment is directly taken from the default template of react-native. Instead of customizing it here, it might be better to keep it in sync. If you think lower-casing is better, should we open a PR on react-native?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Instead of customizing it here, it might be better to keep it in sync.

+1, keeping in sync for now, at least

If you think lower-casing is better, should we open a PR on react-native?

+1 (I will deal with this sometime later)

I did push another change to add a reference to the Facebook template source, on stable branch for 0.60.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is your project, it's really up to you how much you want these boilerplate files to diverge from the official template. :) It's good to merge, please go ahead, so I can rebase #135 - I'll be on a flight and unavailable later today ;)

}

def configureReactNativePom(def pom) {
Expand Down Expand Up @@ -86,7 +90,8 @@ def configureReactNativePom(def pom) {
}

afterEvaluate { project ->

Copy link
Owner Author

Choose a reason for hiding this comment

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

comments would be nice in this afterEvaluate block, which I don't really understand at this point

Copy link
Contributor

Choose a reason for hiding this comment

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

It is related to the different phases of Gradle. The execution phase starts after the configuration phase, and this afterEvaluate block will run in between. Read more here: https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html

// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
Expand Down Expand Up @@ -122,7 +127,6 @@ afterEvaluate { project ->
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://\${projectDir}/../android/maven"

configureReactNativePom pom
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ sdk.dir=/Users/{username}/Library/Android/sdk
},
Object {
"name": "react-native-integration-view-test-package/android/build.gradle",
"theContent": "buildscript {
"theContent": "// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
Expand Down Expand Up @@ -152,18 +154,17 @@ def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
}

repositories {
Expand All @@ -178,7 +179,10 @@ repositories {
}

dependencies {
implementation \\"com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}\\"
// ref:
// https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
Expand Down Expand Up @@ -210,7 +214,8 @@ def configureReactNativePom(def pom) {
}

afterEvaluate { project ->

// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
Expand Down Expand Up @@ -246,7 +251,6 @@ afterEvaluate { project ->
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: \\"file://\${projectDir}/../android/maven\\"

configureReactNativePom pom
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ sdk.dir=/Users/{username}/Library/Android/sdk
},
Object {
"name": "react-native-integration-test-package/android/build.gradle",
"theContent": "buildscript {
"theContent": "// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
Expand Down Expand Up @@ -152,18 +154,17 @@ def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
}

repositories {
Expand All @@ -178,7 +179,10 @@ repositories {
}

dependencies {
implementation \\"com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}\\"
// ref:
// https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
Expand Down Expand Up @@ -210,7 +214,8 @@ def configureReactNativePom(def pom) {
}

afterEvaluate { project ->

// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
Expand Down Expand Up @@ -246,7 +251,6 @@ afterEvaluate { project ->
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: \\"file://\${projectDir}/../android/maven\\"

configureReactNativePom pom
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ content:
"* outputFile name: react-native-alice-bobbi/android/build.gradle
content:
--------
// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand Down Expand Up @@ -227,18 +229,17 @@ def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
}

repositories {
Expand All @@ -253,7 +254,10 @@ repositories {
}

dependencies {
implementation \\"com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}\\"
// ref:
// https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
Expand Down Expand Up @@ -285,7 +289,8 @@ def configureReactNativePom(def pom) {
}

afterEvaluate { project ->

// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
Expand Down Expand Up @@ -321,7 +326,6 @@ afterEvaluate { project ->
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: \\"file://\${projectDir}/../android/maven\\"

configureReactNativePom pom
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ example
"* outputFile name: react-native-alice-bobbi/android/build.gradle
content:
--------
// android/build.gradle

buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand Down Expand Up @@ -232,18 +234,17 @@ def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName \\"1.0\\"
}
lintOptions {
abortOnError false
}
}

repositories {
Expand All @@ -258,7 +259,10 @@ repositories {
}

dependencies {
implementation \\"com.facebook.react:react-native:\${safeExtGet('reactnativeVersion', '+')}\\"
// ref:
// https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
Expand Down Expand Up @@ -290,7 +294,8 @@ def configureReactNativePom(def pom) {
}

afterEvaluate { project ->

// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
Expand Down Expand Up @@ -326,7 +331,6 @@ afterEvaluate { project ->
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: \\"file://\${projectDir}/../android/maven\\"

configureReactNativePom pom
}
}
Expand Down
Loading