From 796eb934c3c90e852b4be21533b7c872acf14ba9 Mon Sep 17 00:00:00 2001 From: SAEED Date: Wed, 8 Jan 2020 14:10:52 +0330 Subject: [PATCH] Load Android Gradle Plugin conditionally --- templates/android.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/templates/android.js b/templates/android.js index fd582ba..87439b7 100644 --- a/templates/android.js +++ b/templates/android.js @@ -1,14 +1,18 @@ module.exports = platform => [{ name: () => `${platform}/build.gradle`, content: ({ packageIdentifier }) => `buildscript { - repositories { - jcenter() - } + // 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 { - // Matches the RN Hello World template - // https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L8 - classpath 'com.android.tools.build:gradle:2.2.3' + dependencies { + classpath("com.android.tools.build:gradle:3.5.3") + } } } @@ -19,18 +23,13 @@ def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } -def DEFAULT_COMPILE_SDK_VERSION = 27 -def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3" -def DEFAULT_MIN_SDK_VERSION = 16 -def DEFAULT_TARGET_SDK_VERSION = 27 - android { - compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) - buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) + compileSdkVersion safeExtGet('compileSdkVersion', 28) + buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3') defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) - targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) + minSdkVersion safeExtGet('minSdkVersion', 16) + targetSdkVersion safeExtGet('targetSdkVersion', 28) versionCode 1 versionName "1.0" } @@ -40,6 +39,7 @@ android { } repositories { + google() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm // Matches the RN Hello World template @@ -50,7 +50,7 @@ repositories { } dependencies { - compile 'com.facebook.react:react-native:+' + implementation 'com.facebook.react:react-native:+' } def configureReactNativePom(def pom) {