From 68ce9a8b3d8471e57e6ab41310c7a7cd8b60afeb Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Mon, 14 May 2018 13:05:13 -0400 Subject: [PATCH 1/5] Add Kotlin support --- bin/templates/project/Activity.kt | 38 +++++++++++ bin/templates/project/app/build.gradle | 10 ++- test/app/build.gradle | 5 ++ .../unittests/KotlinStandardActivityTest.kt | 66 +++++++++++++++++++ test/build.gradle | 2 + test/gradle/wrapper/gradle-wrapper.properties | 3 +- 6 files changed, 119 insertions(+), 5 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 479b46dbaf..c2210d6843 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() jcenter() @@ -30,13 +32,14 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } // Allow plugins to declare Maven dependencies via build-extras.gradle. allprojects { repositories { - mavenCentral(); + mavenCentral() jcenter() } } @@ -51,11 +54,11 @@ ext { apply from: '../CordovaLib/cordova.gradle' // 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')) { @@ -257,6 +260,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/app/build.gradle b/test/app/build.gradle index d63d8ff44e..e16f605107 100644 --- a/test/app/build.gradle +++ b/test/app/build.gradle @@ -17,6 +17,7 @@ */ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' android { compileSdkVersion 27 @@ -49,4 +50,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/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" + } + +} diff --git a/test/build.gradle b/test/build.gradle index d708e97c37..f4a538dc33 100644 --- a/test/build.gradle +++ b/test/build.gradle @@ -19,12 +19,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.2.41' repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' + 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 diff --git a/test/gradle/wrapper/gradle-wrapper.properties b/test/gradle/wrapper/gradle-wrapper.properties index c83ef6eaa7..933b6473ce 100644 --- a/test/gradle/wrapper/gradle-wrapper.properties +++ b/test/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Oct 25 11:17:25 PDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip From 478450fe4fe6a7b06e15d2b68facf0aecd63a27e Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 11 Sep 2018 09:47:55 -0400 Subject: [PATCH 2/5] Address comments --- bin/templates/project/Activity.kt | 38 -------------------------- bin/templates/project/app/build.gradle | 16 ++++++++--- test/build.gradle | 2 +- 3 files changed, 13 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 e38762c51d..1c3926a555 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() maven { @@ -32,7 +34,9 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } } } @@ -260,7 +264,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/build.gradle b/test/build.gradle index f4a538dc33..9759c369e4 100644 --- a/test/build.gradle +++ b/test/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 { jcenter() google() From 67d6dfff3ea51864ff934d566e0916e412eb5d20 Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 7 May 2019 10:57:31 -0400 Subject: [PATCH 3/5] 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 ecb15e1f11..d5e34814ea 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -57,11 +57,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 bbcbaffc7cc1c875ab4184d7f565fa585ce40683 Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 7 May 2019 11:40:50 -0400 Subject: [PATCH 4/5] Bump kotlin version --- bin/templates/project/app/build.gradle | 2 +- test/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 d5e34814ea..65b016efd4 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/build.gradle b/test/build.gradle index 8c4803b25f..85e4459cb0 100644 --- a/test/build.gradle +++ b/test/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 53b3a9cc9ab23e07224cb2226221ea434506247a Mon Sep 17 00:00:00 2001 From: Joshua Chandler Date: Tue, 7 May 2019 12:04:15 -0400 Subject: [PATCH 5/5] Apply cdvHelper function in dependency scope --- 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 65b016efd4..c9351896f3 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -31,6 +31,8 @@ buildscript { } dependencies { + apply from: '../../framework/cordova.gradle' + classpath 'com.android.tools.build:gradle:3.3.0' if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"