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:
parent
9240536afa
commit
2639d523e9
|
@ -1,21 +1,22 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
//Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
ext.getExtOrDefault = {name ->
|
||||||
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['ReactNativeWebView_kotlinVersion']
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebView_' + name]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
classpath("com.android.tools.build:gradle:3.6.0")
|
||||||
//noinspection DifferentKotlinGradleVersion
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}")
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getExtOrDefault(name) {
|
|
||||||
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebView_' + name]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def getExtOrIntegerDefault(name) {
|
def getExtOrIntegerDefault(name) {
|
||||||
|
|
Loading…
Reference in New Issue