mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
feat: add kotlin support (#896)
Co-authored-by: Joshua Chandler <joshchandler88@gmail.com>
This commit is contained in:
parent
d01ed80a61
commit
dee1e77d0b
1
.gitignore
vendored
1
.gitignore
vendored
@ -54,3 +54,4 @@ package-lock.json
|
||||
# Eclipse Buildship files
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
|
5
bin/templates/cordova/lib/prepare.js
vendored
5
bin/templates/cordova/lib/prepare.js
vendored
@ -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 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 (isGradlePluginKotlinEnabled) {
|
||||
gradlePropertiesUserConfig['kotlin.code.style'] = gradlePluginKotlinCodeStyle || 'official';
|
||||
}
|
||||
|
||||
// Both 'useAndroidX' and 'enableJetifier' are linked together.
|
||||
if (androidXEnabled) {
|
||||
|
@ -19,7 +19,31 @@
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
}
|
||||
|
||||
buildscript {
|
||||
apply from: '../CordovaLib/cordova.gradle'
|
||||
|
||||
if(cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||
String defaultGradlePluginKotlinVersion = kotlin_version
|
||||
|
||||
/**
|
||||
* Fetches the user's defined Kotlin Version from config.xml.
|
||||
* If the version is not set or invalid, it will default to the ${defaultGradlePluginKotlinVersion}
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
// Change the version to be used.
|
||||
ext.kotlin_version = gradlePluginKotlinVersion
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
@ -31,6 +55,10 @@ buildscript {
|
||||
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
|
||||
if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
|
||||
if(cdvHelpers.getConfigPreference('GradlePluginGoogleServicesEnabled', 'false').toBoolean()) {
|
||||
String defaultGradlePluginGoogleServicesVersion = '4.2.0'
|
||||
|
||||
@ -301,6 +329,10 @@ android {
|
||||
if (cdvDebugSigningPropertiesFile) {
|
||||
addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -312,6 +344,11 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||
|
||||
if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
|
||||
// SUB-PROJECT DEPENDENCIES START
|
||||
debugCompile(project(path: ":CordovaLib", configuration: "debug"))
|
||||
releaseCompile(project(path: ":CordovaLib", configuration: "release"))
|
||||
|
@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
@ -51,4 +53,9 @@ dependencies {
|
||||
implementation 'com.android.support:appcompat-v7:26.1.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.json:json:20140107'
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
// 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()
|
||||
@ -29,6 +31,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"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user