diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index ea26195fc6..c9351896f3 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -18,8 +18,12 @@ */ apply plugin: 'com.android.application' +if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) { + apply plugin: 'kotlin-android' +} buildscript { + ext.kotlin_version = '1.3.31' repositories { mavenCentral() google() @@ -27,7 +31,12 @@ 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" + } } } @@ -291,6 +300,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: '*.jar') + + 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/app/build.gradle b/test/app/build.gradle index 7c43f84728..03e0c6439d 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 28 @@ -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/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 c9bf1e7d7d..85e4459cb0 100644 --- a/test/build.gradle +++ b/test/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.3.31' repositories { google() jcenter() @@ -29,6 +30,7 @@ buildscript { // in the individual module build.gradle files classpath 'com.android.tools.build:gradle:3.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }