From 2639d523e9336f5f640475bafd058f82f2bc0ab4 Mon Sep 17 00:00:00 2001 From: SaeedZhiany Date: Wed, 27 May 2020 02:27:40 +0430 Subject: [PATCH] fix(gradle): Load Android Gradle Plugin conditionally (#1230 by @SaeedZhiany) BREAKING CHANGE: The Android Gradle plugin is only required when opening the project stand-alone, not when it is included as a dependency. By doing this, the project opens correctly in Android Studio, and it can also be consumed as a native module dependency from an application project without affecting the app project (avoiding unnecessary downloads/conflicts/etc). Also moved getExtOrDefault to buildScript block to able to use everywhere in the file This change shouldn't break any apps, but we are marking it as a breaking change in case there are some use cases we've missed. [skip ci] --- android/build.gradle | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a60fa3e..a5c7275 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,21 +1,22 @@ buildscript { - //Buildscript is evaluated before everything else so we can't use getExtOrDefault - def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['ReactNativeWebView_kotlinVersion'] - - repositories { - google() - jcenter() + ext.getExtOrDefault = {name -> + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebView_' + name] } - dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - //noinspection DifferentKotlinGradleVersion - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} + // 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() + } -def getExtOrDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebView_' + name] + dependencies { + classpath("com.android.tools.build:gradle:3.6.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}") + } + } } def getExtOrIntegerDefault(name) {