From 25ddde1228b357e47e29e8f28b8305f6e52fd024 Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Mon, 14 May 2018 13:05:13 -0400 Subject: [PATCH 01/19] Add Kotlin support --- bin/templates/project/Activity.kt | 38 +++++++++++ bin/templates/project/app/build.gradle | 8 ++- test/android/app/build.gradle | 5 ++ test/android/build.gradle | 2 + .../unittests/KotlinStandardActivityTest.kt | 66 +++++++++++++++++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 bin/templates/project/Activity.kt create mode 100644 test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt diff --git a/bin/templates/project/Activity.kt b/bin/templates/project/Activity.kt new file mode 100644 index 0000000000..2c40b4a415 --- /dev/null +++ b/bin/templates/project/Activity.kt @@ -0,0 +1,38 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +package __ID__; + +import android.os.Bundle; +import org.apache.cordova.*; + +class __ACTIVITY__ : CordovaActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // enable Cordova apps to be started in the background + val extras = intent.extras + if (extras != null && extras.getBoolean("cdvStartInBackground", false)) { + moveTaskToBack(true) + } + + // Set by in config.xml + loadUrl(launchUrl) + } +} diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 29503bdb88..7c985d812b 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -18,8 +18,10 @@ */ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' buildscript { + ext.kotlin_version = '1.2.41' repositories { mavenCentral() google() @@ -30,6 +32,7 @@ buildscript { apply from: '../CordovaLib/cordova.gradle' classpath 'com.android.tools.build:gradle:3.5.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" if(cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) { String defaultGradlePluginGoogleServicesVersion = '4.2.0' @@ -71,11 +74,11 @@ ext { // The value for android.compileSdkVersion. if (!project.hasProperty('cdvCompileSdkVersion')) { - cdvCompileSdkVersion = null; + cdvCompileSdkVersion = null } // The value for android.buildToolsVersion. if (!project.hasProperty('cdvBuildToolsVersion')) { - cdvBuildToolsVersion = null; + cdvBuildToolsVersion = null } // Sets the versionCode to the given value. if (!project.hasProperty('cdvVersionCode')) { @@ -312,6 +315,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: '*.jar') + compile "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/test/android/app/build.gradle b/test/android/app/build.gradle index 33eb937dab..a3ac00c3c8 100644 --- a/test/android/app/build.gradle +++ b/test/android/app/build.gradle @@ -17,6 +17,7 @@ */ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' android { compileSdkVersion 29 @@ -51,4 +52,8 @@ dependencies { implementation 'com.android.support:appcompat-v7:26.1.0' testImplementation 'junit:junit:4.12' testImplementation 'org.json:json:20140107' + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/test/android/build.gradle b/test/android/build.gradle index fbfcb2723f..a24fed7e31 100644 --- a/test/android/build.gradle +++ b/test/android/build.gradle @@ -19,6 +19,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.2.41' repositories { google() jcenter() @@ -29,6 +30,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" } } diff --git a/test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt b/test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt new file mode 100644 index 0000000000..b259d284a3 --- /dev/null +++ b/test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt @@ -0,0 +1,66 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +package org.apache.cordova.unittests + +import android.content.Intent +import android.support.test.rule.ActivityTestRule +import android.support.test.runner.AndroidJUnit4 + +import org.apache.cordova.engine.SystemWebView +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +import junit.framework.Assert.assertEquals + +/** + * The purpose of this test is to test the default application that is generated by Cordova itself + * + */ +@RunWith(AndroidJUnit4::class) +public class KotlinStandardActivityTest { + + // Don't launch the activity, we're going to send it intents + @get:Rule + var mActivityRule = ActivityTestRule( + StandardActivity::class.java, true, false) + + @Before + fun launchApplicationWithIntent() { + val intent = Intent() + intent.putExtra("startUrl", FALSE_URI) + intent.putExtra("backgroundcolor", "#0000ff") + mActivityRule.launchActivity(intent) + } + + @Test + fun webViewCheck() { + val activity = mActivityRule.getActivity() as StandardActivity + //Fish the webview out of the mostly locked down Activity using the Android SDK + val view = activity.getWindow().getCurrentFocus() + assertEquals(SystemWebView::class, view::class) + } + + companion object { + private val FALSE_URI = "http://www.google.com" + } + +} From 3bf8cf9e4fcd702175ce78d6d96d73e3ab179e7f Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 11 Sep 2018 09:47:55 -0400 Subject: [PATCH 02/19] Address comments --- bin/templates/project/Activity.kt | 38 -------------------------- bin/templates/project/app/build.gradle | 17 +++++++++--- test/android/build.gradle | 2 +- 3 files changed, 14 insertions(+), 43 deletions(-) delete mode 100644 bin/templates/project/Activity.kt diff --git a/bin/templates/project/Activity.kt b/bin/templates/project/Activity.kt deleted file mode 100644 index 2c40b4a415..0000000000 --- a/bin/templates/project/Activity.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -package __ID__; - -import android.os.Bundle; -import org.apache.cordova.*; - -class __ACTIVITY__ : CordovaActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - // enable Cordova apps to be started in the background - val extras = intent.extras - if (extras != null && extras.getBoolean("cdvStartInBackground", false)) { - moveTaskToBack(true) - } - - // Set by in config.xml - loadUrl(launchUrl) - } -} diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 7c985d812b..dc3adf5f27 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -18,10 +18,12 @@ */ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' +if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + apply plugin: 'kotlin-android' +} buildscript { - ext.kotlin_version = '1.2.41' + ext.kotlin_version = '1.2.61' repositories { mavenCentral() google() @@ -32,7 +34,10 @@ buildscript { apply from: '../CordovaLib/cordova.gradle' classpath 'com.android.tools.build:gradle:3.5.3' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } if(cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) { String defaultGradlePluginGoogleServicesVersion = '4.2.0' @@ -315,7 +320,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: '*.jar') - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + + if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + compile "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/test/android/build.gradle b/test/android/build.gradle index a24fed7e31..baa9e19abd 100644 --- a/test/android/build.gradle +++ b/test/android/build.gradle @@ -19,7 +19,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.41' + ext.kotlin_version = '1.2.61' repositories { google() jcenter() From b6b480b4a3299349f2d928c766f35c9a82801e20 Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 7 May 2019 10:57:31 -0400 Subject: [PATCH 03/19] Remove whitespace changes --- bin/templates/project/app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index dc3adf5f27..540d76df88 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -79,11 +79,11 @@ ext { // The value for android.compileSdkVersion. if (!project.hasProperty('cdvCompileSdkVersion')) { - cdvCompileSdkVersion = null + cdvCompileSdkVersion = null; } // The value for android.buildToolsVersion. if (!project.hasProperty('cdvBuildToolsVersion')) { - cdvBuildToolsVersion = null + cdvBuildToolsVersion = null; } // Sets the versionCode to the given value. if (!project.hasProperty('cdvVersionCode')) { From c9bac72ca432ce982a750a37e8dd890ac7174b8c Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 7 May 2019 11:40:50 -0400 Subject: [PATCH 04/19] Bump kotlin version --- bin/templates/project/app/build.gradle | 2 +- test/android/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 540d76df88..e384a50818 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -23,7 +23,7 @@ if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { } buildscript { - ext.kotlin_version = '1.2.61' + ext.kotlin_version = '1.3.31' repositories { mavenCentral() google() diff --git a/test/android/build.gradle b/test/android/build.gradle index baa9e19abd..2e851ddde4 100644 --- a/test/android/build.gradle +++ b/test/android/build.gradle @@ -19,7 +19,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.61' + ext.kotlin_version = '1.3.31' repositories { google() jcenter() From 6bdb18a63b4025505a7ec78a6d5c605daa57922a Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 09:12:10 +0900 Subject: [PATCH 05/19] chore: rename preference option to KotlinEnabled --- bin/templates/project/app/build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index e384a50818..d54efced16 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -18,7 +18,8 @@ */ apply plugin: 'com.android.application' -if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + +if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { apply plugin: 'kotlin-android' } @@ -35,7 +36,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.5.3' - if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } @@ -321,7 +322,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: '*.jar') - if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } From f0fe1ba9141e7f16ed53d5c318e07051871affd6 Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 09:12:36 +0900 Subject: [PATCH 06/19] chore: include kotlin android extensions plugin --- bin/templates/project/app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index d54efced16..ec39b384eb 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -21,6 +21,7 @@ apply plugin: 'com.android.application' if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { apply plugin: 'kotlin-android' + apply plugin: 'kotlin-android-extensions' } buildscript { From 2009f3acdbb3b30e73a3430370f92cec55484de1 Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 10:16:35 +0900 Subject: [PATCH 07/19] feat: add Kotlin Code Style support (default=official) --- bin/templates/cordova/lib/prepare.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js index a8d120d479..804bbb0156 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 isKotlinEnabled = this._config.getPreference('KotlinEnabled', 'android'); + const kotlinCodeStyle = this._config.getPreference('KotlinCodeStyle', 'android'); let gradlePropertiesUserConfig = {}; if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion; if (maxSdkVersion) gradlePropertiesUserConfig.cdvMaxSdkVersion = maxSdkVersion; if (targetSdkVersion) gradlePropertiesUserConfig.cdvTargetSdkVersion = targetSdkVersion; + if (isKotlinEnabled) { + gradlePropertiesUserConfig['kotlin.code.style'] = kotlinCodeStyle ? kotlinCodeStyle : 'official'; + } // Both 'useAndroidX' and 'enableJetifier' are linked together. if (androidXEnabled) { From e9bd0494bebdad0d1a03d9db9d89873ac610d4fb Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 10:22:16 +0900 Subject: [PATCH 08/19] chore: bump kotlin version --- bin/templates/project/app/build.gradle | 2 +- test/android/build.gradle | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index ec39b384eb..4c8a49bad5 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -25,7 +25,7 @@ if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { } buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.41' repositories { mavenCentral() google() diff --git a/test/android/build.gradle b/test/android/build.gradle index 2e851ddde4..90566f4f12 100644 --- a/test/android/build.gradle +++ b/test/android/build.gradle @@ -19,7 +19,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.41' + repositories { google() jcenter() From fbe7cc1fa1dfe7cbd55c69ae615a9f97a47d574f Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 10:22:45 +0900 Subject: [PATCH 09/19] chore: update kotlin dependencies from apply to implementation --- bin/templates/project/app/build.gradle | 2 +- test/android/app/build.gradle | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 4c8a49bad5..8b37dc2ec9 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -324,7 +324,7 @@ dependencies { implementation fileTree(dir: 'libs', include: '*.jar') if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } // SUB-PROJECT DEPENDENCIES START diff --git a/test/android/app/build.gradle b/test/android/app/build.gradle index a3ac00c3c8..5dade914fc 100644 --- a/test/android/app/build.gradle +++ b/test/android/app/build.gradle @@ -52,7 +52,8 @@ dependencies { implementation 'com.android.support:appcompat-v7:26.1.0' testImplementation 'junit:junit:4.12' testImplementation 'org.json:json:20140107' - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } repositories { mavenCentral() From 120e2638033bf5aea2ce5dc5cfe5e3e7e6b78fad Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 10:34:12 +0900 Subject: [PATCH 10/19] feat: add support for KotlinVersion preference option --- bin/templates/project/app/build.gradle | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 8b37dc2ec9..3da1c765cb 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -25,7 +25,22 @@ if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { } buildscript { - ext.kotlin_version = '1.3.41' + if(cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { + String defaultKotlinVersion = '1.3.41' + + /** + * Fetches the user's defined Kotlin Version from config.xml. + * If the version is not set or invalid, it will default to the ${defaultKotlinVersion} + */ + String kotlinVersion = cdvHelpers.getConfigPreference('KotlinVersion', defaultKotlinVersion) + if(!cdvHelpers.isVersionValid(kotlinVersion)) { + println("The defined Kotlin version (${kotlinVersion}) does not appear to be a valid version. Falling back to version: ${defaultKotlinVersion}.") + kotlinVersion = defaultKotlinVersion + } + + ext.kotlin_version = kotlinVersion + } + repositories { mavenCentral() google() From 949317f7988a02425240fe9d78782f6d33bd9b9c Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 10:40:40 +0900 Subject: [PATCH 11/19] feat: add kotlin android extensions to test app --- test/android/app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/test/android/app/build.gradle b/test/android/app/build.gradle index 5dade914fc..9789643ff8 100644 --- a/test/android/app/build.gradle +++ b/test/android/app/build.gradle @@ -18,6 +18,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 From 51fc9a66c525cce3247c033223ab7648e83eb8a6 Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 10:47:58 +0900 Subject: [PATCH 12/19] chore: add missing apply to cdvhelper in buildscript --- bin/templates/project/app/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 3da1c765cb..cee2d96d1d 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -25,6 +25,8 @@ if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { } buildscript { + apply from: '../CordovaLib/cordova.gradle' + if(cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { String defaultKotlinVersion = '1.3.41' From 04a407b64878cd5875c86b0695f1c2ea47eb3d97 Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 14:28:11 +0900 Subject: [PATCH 13/19] chore: lint correction --- bin/templates/cordova/lib/prepare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js index 804bbb0156..7ff0f089d5 100644 --- a/bin/templates/cordova/lib/prepare.js +++ b/bin/templates/cordova/lib/prepare.js @@ -54,7 +54,7 @@ module.exports.prepare = function (cordovaProject, options) { if (maxSdkVersion) gradlePropertiesUserConfig.cdvMaxSdkVersion = maxSdkVersion; if (targetSdkVersion) gradlePropertiesUserConfig.cdvTargetSdkVersion = targetSdkVersion; if (isKotlinEnabled) { - gradlePropertiesUserConfig['kotlin.code.style'] = kotlinCodeStyle ? kotlinCodeStyle : 'official'; + gradlePropertiesUserConfig['kotlin.code.style'] = kotlinCodeStyle || 'official'; } // Both 'useAndroidX' and 'enableJetifier' are linked together. From 13c725528a9e4be91a793a3fba1eeb3fcc10ee2b Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 14:33:37 +0900 Subject: [PATCH 14/19] chore: use jcenter instead of mavenCentral --- test/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/android/app/build.gradle b/test/android/app/build.gradle index 9789643ff8..88698a35bb 100644 --- a/test/android/app/build.gradle +++ b/test/android/app/build.gradle @@ -57,5 +57,5 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } repositories { - mavenCentral() + jcenter() } From 764e7b27468c4fb4c9287c0a7c22e18dc34547fd Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 14:56:06 +0900 Subject: [PATCH 15/19] feat: add kotlin to sourceSets --- bin/templates/project/app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index cee2d96d1d..02e41491ef 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -328,6 +328,10 @@ android { if (cdvDebugSigningPropertiesFile) { addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug) } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } } /* From 704c5024785fc0fd967d77cb2f31b153bf3bb905 Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 18:07:14 +0900 Subject: [PATCH 16/19] chore: removed KotlinStandardActivityTest.kt --- .../unittests/KotlinStandardActivityTest.kt | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt diff --git a/test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt b/test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt deleted file mode 100644 index b259d284a3..0000000000 --- a/test/app/src/androidTest/java/org/apache/cordova/unittests/KotlinStandardActivityTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -package org.apache.cordova.unittests - -import android.content.Intent -import android.support.test.rule.ActivityTestRule -import android.support.test.runner.AndroidJUnit4 - -import org.apache.cordova.engine.SystemWebView -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -import junit.framework.Assert.assertEquals - -/** - * The purpose of this test is to test the default application that is generated by Cordova itself - * - */ -@RunWith(AndroidJUnit4::class) -public class KotlinStandardActivityTest { - - // Don't launch the activity, we're going to send it intents - @get:Rule - var mActivityRule = ActivityTestRule( - StandardActivity::class.java, true, false) - - @Before - fun launchApplicationWithIntent() { - val intent = Intent() - intent.putExtra("startUrl", FALSE_URI) - intent.putExtra("backgroundcolor", "#0000ff") - mActivityRule.launchActivity(intent) - } - - @Test - fun webViewCheck() { - val activity = mActivityRule.getActivity() as StandardActivity - //Fish the webview out of the mostly locked down Activity using the Android SDK - val view = activity.getWindow().getCurrentFocus() - assertEquals(SystemWebView::class, view::class) - } - - companion object { - private val FALSE_URI = "http://www.google.com" - } - -} From 97f64712ad1f82768008ceb41e29993ebab638bb Mon Sep 17 00:00:00 2001 From: Erisu Date: Thu, 16 Jan 2020 21:22:54 +0900 Subject: [PATCH 17/19] chore: rename preference options --- bin/templates/cordova/lib/prepare.js | 8 ++++---- bin/templates/project/app/build.gradle | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js index 7ff0f089d5..14abcee495 100644 --- a/bin/templates/cordova/lib/prepare.js +++ b/bin/templates/cordova/lib/prepare.js @@ -46,15 +46,15 @@ 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 isKotlinEnabled = this._config.getPreference('KotlinEnabled', 'android'); - const kotlinCodeStyle = this._config.getPreference('KotlinCodeStyle', '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 (isKotlinEnabled) { - gradlePropertiesUserConfig['kotlin.code.style'] = kotlinCodeStyle || 'official'; + if (isGradlePluginKotlinEnabled) { + gradlePropertiesUserConfig['kotlin.code.style'] = gradlePluginKotlinCodeStyle || 'official'; } // Both 'useAndroidX' and 'enableJetifier' are linked together. diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 02e41491ef..9ceb983a45 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'com.android.application' -if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { +if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) { apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' } @@ -27,20 +27,20 @@ if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { buildscript { apply from: '../CordovaLib/cordova.gradle' - if(cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { - String defaultKotlinVersion = '1.3.41' + if(cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) { + String defaultGradlePluginKotlinVersion = '1.3.41' /** * Fetches the user's defined Kotlin Version from config.xml. - * If the version is not set or invalid, it will default to the ${defaultKotlinVersion} + * If the version is not set or invalid, it will default to the ${defaultGradlePluginKotlinVersion} */ - String kotlinVersion = cdvHelpers.getConfigPreference('KotlinVersion', defaultKotlinVersion) - if(!cdvHelpers.isVersionValid(kotlinVersion)) { - println("The defined Kotlin version (${kotlinVersion}) does not appear to be a valid version. Falling back to version: ${defaultKotlinVersion}.") - kotlinVersion = defaultKotlinVersion + 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 } - ext.kotlin_version = kotlinVersion + ext.kotlin_version = gradlePluginKotlinVersion } repositories { @@ -54,7 +54,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.5.3' - if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { + if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } @@ -344,7 +344,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: '*.jar') - if (cdvHelpers.getConfigPreference('KotlinEnabled', 'false').toBoolean()) { + if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } From 312118775575075aebe16ac24f78315856e582bd Mon Sep 17 00:00:00 2001 From: Erisu Date: Sat, 18 Jan 2020 14:37:33 +0900 Subject: [PATCH 18/19] chore: bump kotlin to 1.3.50 --- bin/templates/project/app/build.gradle | 3 ++- bin/templates/project/build.gradle | 6 +++--- test/android/build.gradle | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index 9ceb983a45..de22c37aef 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -28,7 +28,7 @@ buildscript { apply from: '../CordovaLib/cordova.gradle' if(cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) { - String defaultGradlePluginKotlinVersion = '1.3.41' + String defaultGradlePluginKotlinVersion = ext.kotlin_version /** * Fetches the user's defined Kotlin Version from config.xml. @@ -40,6 +40,7 @@ buildscript { gradlePluginKotlinVersion = defaultGradlePluginKotlinVersion } + // Change the version to be used. ext.kotlin_version = gradlePluginKotlinVersion } diff --git a/bin/templates/project/build.gradle b/bin/templates/project/build.gradle index 3c9aa71270..b39038e9aa 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/build.gradle b/test/android/build.gradle index 90566f4f12..83d8f6350c 100644 --- a/test/android/build.gradle +++ b/test/android/build.gradle @@ -19,7 +19,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.41' + ext.kotlin_version = '1.3.50' repositories { google() From 99ee5d05ebc8e85e9af34eacc6ecffba0cda6436 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 24 Jan 2020 20:20:52 +0900 Subject: [PATCH 19/19] chore: fix setting kotlin version --- .gitignore | 1 + bin/templates/project/app/build.gradle | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4c093a9be3..e7a9156292 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ package-lock.json # Eclipse Buildship files .project .settings +.classpath diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index de22c37aef..fdbb725456 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -28,7 +28,7 @@ buildscript { apply from: '../CordovaLib/cordova.gradle' if(cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) { - String defaultGradlePluginKotlinVersion = ext.kotlin_version + String defaultGradlePluginKotlinVersion = kotlin_version /** * Fetches the user's defined Kotlin Version from config.xml.