Skip to content

Commit 796eb93

Browse files
committed
Load Android Gradle Plugin conditionally
1 parent e08c03c commit 796eb93

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

templates/android.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
module.exports = platform => [{
22
name: () => `${platform}/build.gradle`,
33
content: ({ packageIdentifier }) => `buildscript {
4-
repositories {
5-
jcenter()
6-
}
4+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
5+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
6+
// module dependency in an application project.
7+
if (project == rootProject) {
8+
repositories {
9+
google()
10+
jcenter()
11+
}
712
8-
dependencies {
9-
// Matches the RN Hello World template
10-
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L8
11-
classpath 'com.android.tools.build:gradle:2.2.3'
13+
dependencies {
14+
classpath("com.android.tools.build:gradle:3.5.3")
15+
}
1216
}
1317
}
1418
@@ -19,18 +23,13 @@ def safeExtGet(prop, fallback) {
1923
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
2024
}
2125
22-
def DEFAULT_COMPILE_SDK_VERSION = 27
23-
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
24-
def DEFAULT_MIN_SDK_VERSION = 16
25-
def DEFAULT_TARGET_SDK_VERSION = 27
26-
2726
android {
28-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
29-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
27+
compileSdkVersion safeExtGet('compileSdkVersion', 28)
28+
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
3029
3130
defaultConfig {
32-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
33-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
31+
minSdkVersion safeExtGet('minSdkVersion', 16)
32+
targetSdkVersion safeExtGet('targetSdkVersion', 28)
3433
versionCode 1
3534
versionName "1.0"
3635
}
@@ -40,6 +39,7 @@ android {
4039
}
4140
4241
repositories {
42+
google()
4343
maven {
4444
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
4545
// Matches the RN Hello World template
@@ -50,7 +50,7 @@ repositories {
5050
}
5151
5252
dependencies {
53-
compile 'com.facebook.react:react-native:+'
53+
implementation 'com.facebook.react:react-native:+'
5454
}
5555
5656
def configureReactNativePom(def pom) {

0 commit comments

Comments
 (0)