From 5ce5e72b3a90803fc4b54555cd0e8b900c756d9e Mon Sep 17 00:00:00 2001 From: ypbnv Date: Wed, 15 Jan 2020 18:04:20 +0200 Subject: [PATCH] feat(android): target Java8 and Kotlin support for native modules targets Java 8 and adds support for Kotlin for developing native android modules --- android/app/build.gradle | 4 ++++ android/build.gradle | 3 +++ android/kroll-apt/build.gradle | 4 ++-- .../kroll/annotations/generator/KrollJSONGenerator.java | 2 +- android/templates/build/app.build.gradle | 4 ++-- android/templates/build/root.build.gradle | 3 +++ android/templates/module/generated/build.gradle | 9 +++++++-- android/titanium/build.gradle | 4 ++-- 8 files changed, 24 insertions(+), 9 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index c538f3d9294..378dd030525 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -29,6 +29,10 @@ android { ] } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/android/build.gradle b/android/build.gradle index e518567844d..ca04f15b356 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -6,12 +6,15 @@ */ buildscript { + ext.kotlin_version = '1.3.61' + repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/android/kroll-apt/build.gradle b/android/kroll-apt/build.gradle index 17dd9c4e949..be6931121e8 100644 --- a/android/kroll-apt/build.gradle +++ b/android/kroll-apt/build.gradle @@ -7,8 +7,8 @@ apply plugin: 'java' -sourceCompatibility = JavaVersion.VERSION_1_7 -targetCompatibility = JavaVersion.VERSION_1_7 +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 tasks.withType(JavaCompile) { // Suppress compiler warning "bootstrap class path not set in conjunction with source" which happens when diff --git a/android/kroll-apt/src/main/java/org/appcelerator/kroll/annotations/generator/KrollJSONGenerator.java b/android/kroll-apt/src/main/java/org/appcelerator/kroll/annotations/generator/KrollJSONGenerator.java index cf49f675323..7c4c01c0e89 100644 --- a/android/kroll-apt/src/main/java/org/appcelerator/kroll/annotations/generator/KrollJSONGenerator.java +++ b/android/kroll-apt/src/main/java/org/appcelerator/kroll/annotations/generator/KrollJSONGenerator.java @@ -36,7 +36,7 @@ import org.json.simple.JSONValue; -@SupportedSourceVersion(SourceVersion.RELEASE_7) +@SupportedSourceVersion(SourceVersion.RELEASE_8) @SuppressWarnings("unchecked") // clang-format off @SupportedAnnotationTypes({ diff --git a/android/templates/build/app.build.gradle b/android/templates/build/app.build.gradle index 6dbcd170425..1e6236ff467 100644 --- a/android/templates/build/app.build.gradle +++ b/android/templates/build/app.build.gradle @@ -31,8 +31,8 @@ android { } // TODO: Add Java 8 support in the future. compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } signingConfigs { def tiKeystoreFilePath = <%- "'" + tiSdkAndroidDir.replace(/\\/g, '\\\\') + "/dev_keystore'" %> diff --git a/android/templates/build/root.build.gradle b/android/templates/build/root.build.gradle index 352d163d23b..0e1a24bc614 100644 --- a/android/templates/build/root.build.gradle +++ b/android/templates/build/root.build.gradle @@ -1,11 +1,14 @@ buildscript { + ext.kotlin_version = '1.3.61' + repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/android/templates/module/generated/build.gradle b/android/templates/module/generated/build.gradle index e47ac609127..f8557f7fa94 100644 --- a/android/templates/module/generated/build.gradle +++ b/android/templates/module/generated/build.gradle @@ -1,6 +1,8 @@ apply plugin: 'com.android.library' apply plugin: 'maven-publish' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' repositories { maven { @@ -120,8 +122,8 @@ android { } // TODO: Add Java 8 support in the future. compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } // Exclude the C++ runtime and Titanium kroll libraries for all architectures when packaging the AAR file. // Avoids app build failure due to library file name collision. (Apps will use "titanium.aar" bundled *.so files.) @@ -158,12 +160,15 @@ dependencies { def krollAptJarPath = '<%- krollAptJarPath.replace(/\\/g, '\\\\') %>' annotationProcessor files(krollAptJarPath) compileOnly files(krollAptJarPath) + kapt files(krollAptJarPath) // Reference this module's local AAR/JAR file dependencies. implementation fileTree(dir: "${projectDir}/../../lib", include: ['*.aar', '*.jar']) // Reference the main Titanium library. implementation 'org.appcelerator:titanium:<%- tiSdkVersion %>' + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } // This block is used when we run "gradlew :module:publish" at the command line. diff --git a/android/titanium/build.gradle b/android/titanium/build.gradle index 608b442e40e..65510a8d2e8 100644 --- a/android/titanium/build.gradle +++ b/android/titanium/build.gradle @@ -105,8 +105,8 @@ android { } // TODO: Add Java 8 support in the future. compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } }