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]
This commit is contained in:
SaeedZhiany 2020-05-27 02:27:40 +04:30 committed by GitHub
parent 9240536afa
commit 2639d523e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 14 deletions

View File

@ -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) {