Skip to content

Commit

Permalink
feat: add preferences to control compiler targets
Browse files Browse the repository at this point in the history
The mapping is pretty straightforward:

AndroidJavaSourceCompatibility > Java Source Files - defaults to (Java) 8
AndroidJavaTargetCompatibility > Java Compiler - defaults to (Java 8
AndroidKotlinJvmTarget > Kotlin Compiler - defaults to '1.8'

AndroidJavaTargetCompatibility and AndroidKotlinJvmTarget should target
the same semantic Java version to avoid build conflicts due to different
JDKs. Only sane defaults are provided, no further checks are performed.

See apache#1678 for more info.

References https://outsystemsrd.atlassian.net/browse/RNMT-6402
  • Loading branch information
EiyuuZack committed Dec 4, 2023
1 parent 9fcfc2e commit e99f960
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ android {
buildToolsVersion cordovaConfig.BUILD_TOOLS_VERSION

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaLanguageVersion.of(cordovaConfig.JAVA_SOURCE_COMPATIBILITY)
targetCompatibility JavaLanguageVersion.of(cordovaConfig.JAVA_TARGET_COMPATIBILITY)
}

// For the Android Cordova Lib, we allow changing the minSdkVersion, but it is at the users own risk
Expand Down
5 changes: 4 additions & 1 deletion framework/cdv-gradle-config-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION": "4.4.0",
"IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": false,
"IS_GRADLE_PLUGIN_KOTLIN_ENABLED": true,
"PACKAGE_NAMESPACE": "io.cordova.helloCordova"
"PACKAGE_NAMESPACE": "io.cordova.helloCordova",
"JAVA_SOURCE_COMPATIBILITY": 8,
"JAVA_TARGET_COMPATIBILITY": 8,
"KOTLIN_JVM_TARGET": "1.8"
}
5 changes: 4 additions & 1 deletion lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ function getUserGradleConfig (configXml) {
{ xmlKey: 'AndroidXCoreSplashscreenVersion', gradleKey: 'ANDROIDX_CORE_SPLASHSCREEN_VERSION', type: String },
{ xmlKey: 'GradlePluginGoogleServicesVersion', gradleKey: 'GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION', type: String },
{ xmlKey: 'GradlePluginGoogleServicesEnabled', gradleKey: 'IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED', type: Boolean },
{ xmlKey: 'GradlePluginKotlinEnabled', gradleKey: 'IS_GRADLE_PLUGIN_KOTLIN_ENABLED', type: Boolean }
{ xmlKey: 'GradlePluginKotlinEnabled', gradleKey: 'IS_GRADLE_PLUGIN_KOTLIN_ENABLED', type: Boolean },
{ xmlKey: 'AndroidJavaSourceCompatibility', gradleKey: 'JAVA_SOURCE_COMPATIBILITY', type: Number },
{ xmlKey: 'AndroidJavaTargetCompatibility', gradleKey: 'JAVA_TARGET_COMPATIBILITY', type: Number },
{ xmlKey: 'AndroidKotlinJvmTarget', gradleKey: 'KOTLIN_JVM_TARGET', type: String }
];

return configXmlToGradleMapping.reduce((config, mapping) => {
Expand Down
6 changes: 3 additions & 3 deletions templates/project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaLanguageVersion.of(cordovaConfig.JAVA_SOURCE_COMPATIBILITY)
targetCompatibility JavaLanguageVersion.of(cordovaConfig.JAVA_TARGET_COMPATIBILITY)
}

if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = cordovaConfig.KOTLIN_JVM_TARGET
}
}

Expand Down

0 comments on commit e99f960

Please sign in to comment.