Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-14089: (android) Add Kotlin support #441

Closed
wants to merge 8 commits into from
14 changes: 14 additions & 0 deletions bin/templates/project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@
*/

apply plugin: 'com.android.application'
if (cdvHelpers.getConfigPreference('EnableKotlin', 'false').toBoolean()) {
apply plugin: 'kotlin-android'
}

buildscript {
ext.kotlin_version = '1.3.31'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.3.61'

repositories {
mavenCentral()
google()
jcenter()
}

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"
}
}
}

Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we require the jdk7 stdlib here? This should be changed to kotlin-stdlib instead.

Suggested change
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

}

// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: ":CordovaLib", configuration: "debug"))
releaseCompile(project(path: ":CordovaLib", configuration: "release"))
Expand Down
5 changes: 5 additions & 0 deletions test/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Suggested change
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

}
repositories {
mavenCentral()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://blog.bintray.com/2015/02/09/android-studio-migration-from-maven-central-to-jcenter/ why jcenter should be used

Suggested change
mavenCentral()
jcenter()

}
Original file line number Diff line number Diff line change
@@ -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"
}

}
2 changes: 2 additions & 0 deletions test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
timbru31 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.3.61'

repositories {
google()
jcenter()
Expand All @@ -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"
}
}

Expand Down