You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2020/01/27 07:15:07 UTC
[cordova-android] branch master updated: feat: add kotlin support
(#896)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new dee1e77 feat: add kotlin support (#896)
dee1e77 is described below
commit dee1e77d0b69aaa1069fd6e21400e3f617ea6e0d
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Mon Jan 27 16:14:58 2020 +0900
feat: add kotlin support (#896)
Co-authored-by: Joshua Chandler <jo...@gmail.com>
---
.gitignore | 1 +
bin/templates/cordova/lib/prepare.js | 5 +++++
bin/templates/project/app/build.gradle | 37 ++++++++++++++++++++++++++++++++++
bin/templates/project/build.gradle | 6 +++---
test/android/app/build.gradle | 7 +++++++
test/android/build.gradle | 3 +++
6 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index 4c093a9..e7a9156 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,3 +54,4 @@ package-lock.json
# Eclipse Buildship files
.project
.settings
+.classpath
diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js
index a8d120d..14abcee 100644
--- a/bin/templates/cordova/lib/prepare.js
+++ b/bin/templates/cordova/lib/prepare.js
@@ -46,11 +46,16 @@ module.exports.prepare = function (cordovaProject, options) {
const maxSdkVersion = this._config.getPreference('android-maxSdkVersion', 'android');
const targetSdkVersion = this._config.getPreference('android-targetSdkVersion', 'android');
const androidXEnabled = this._config.getPreference('AndroidXEnabled', 'android');
+ const isGradlePluginKotlinEnabled = this._config.getPreference('GradlePluginKotlinEnabled', 'android');
+ const gradlePluginKotlinCodeStyle = this._config.getPreference('GradlePluginKotlinCodeStyle', 'android');
let gradlePropertiesUserConfig = {};
if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion;
if (maxSdkVersion) gradlePropertiesUserConfig.cdvMaxSdkVersion = maxSdkVersion;
if (targetSdkVersion) gradlePropertiesUserConfig.cdvTargetSdkVersion = targetSdkVersion;
+ if (isGradlePluginKotlinEnabled) {
+ gradlePropertiesUserConfig['kotlin.code.style'] = gradlePluginKotlinCodeStyle || 'official';
+ }
// Both 'useAndroidX' and 'enableJetifier' are linked together.
if (androidXEnabled) {
diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle
index 29503bd..fdbb725 100644
--- a/bin/templates/project/app/build.gradle
+++ b/bin/templates/project/app/build.gradle
@@ -19,7 +19,31 @@
apply plugin: 'com.android.application'
+if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
+ apply plugin: 'kotlin-android'
+ apply plugin: 'kotlin-android-extensions'
+}
+
buildscript {
+ apply from: '../CordovaLib/cordova.gradle'
+
+ if(cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
+ String defaultGradlePluginKotlinVersion = kotlin_version
+
+ /**
+ * Fetches the user's defined Kotlin Version from config.xml.
+ * If the version is not set or invalid, it will default to the ${defaultGradlePluginKotlinVersion}
+ */
+ String gradlePluginKotlinVersion = cdvHelpers.getConfigPreference('GradlePluginKotlinVersion', defaultGradlePluginKotlinVersion)
+ if(!cdvHelpers.isVersionValid(gradlePluginKotlinVersion)) {
+ println("The defined Kotlin version (${gradlePluginKotlinVersion}) does not appear to be a valid version. Falling back to version: ${defaultGradlePluginKotlinVersion}.")
+ gradlePluginKotlinVersion = defaultGradlePluginKotlinVersion
+ }
+
+ // Change the version to be used.
+ ext.kotlin_version = gradlePluginKotlinVersion
+ }
+
repositories {
mavenCentral()
google()
@@ -31,6 +55,10 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.5.3'
+ if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+
if(cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) {
String defaultGradlePluginGoogleServicesVersion = '4.2.0'
@@ -301,6 +329,10 @@ android {
if (cdvDebugSigningPropertiesFile) {
addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
}
+
+ sourceSets {
+ main.java.srcDirs += 'src/main/kotlin'
+ }
}
/*
@@ -312,6 +344,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
+
+ if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ }
+
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: ":CordovaLib", configuration: "debug"))
releaseCompile(project(path: ":CordovaLib", configuration: "release"))
diff --git a/bin/templates/project/build.gradle b/bin/templates/project/build.gradle
index 3c9aa71..b39038e 100644
--- a/bin/templates/project/build.gradle
+++ b/bin/templates/project/build.gradle
@@ -19,16 +19,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
+ ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
-
dependencies {
+ classpath 'com.android.tools.build:gradle:3.5.3'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
-
- classpath 'com.android.tools.build:gradle:3.5.3'
}
}
diff --git a/test/android/app/build.gradle b/test/android/app/build.gradle
index 33eb937..88698a3 100644
--- a/test/android/app/build.gradle
+++ b/test/android/app/build.gradle
@@ -17,6 +17,8 @@
*/
apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
@@ -51,4 +53,9 @@ dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.json:json:20140107'
+
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+}
+repositories {
+ jcenter()
}
diff --git a/test/android/build.gradle b/test/android/build.gradle
index fbfcb27..83d8f63 100644
--- a/test/android/build.gradle
+++ b/test/android/build.gradle
@@ -19,6 +19,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
+ ext.kotlin_version = '1.3.50'
+
repositories {
google()
jcenter()
@@ -29,6 +31,7 @@ buildscript {
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.5.3'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org