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

Ensure Android Java and Kotlin compile to the same version #61579

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions platform/android/java/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Gradle build config for Godot Engine's Android port.
apply from: 'config.gradle'

Comment on lines -2 to -3
Copy link
Contributor

Choose a reason for hiding this comment

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

This is needed when doing gradle builds in the Godot Editor since in that environment, the app/build.gradle is the root gradle build file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the PR to include apply from: 'config.gradle' below the plugins DSL block (it can't go above).

To get everything to work properly using the plugins DSL, I also needed to update the settings.gradle file for plugin management to enable code based version selection.

I've now tested both the Editor custom build export, and an Android Studio build of the editor to confirm everything works.

buildscript {
apply from: 'config.gradle'

Expand All @@ -14,7 +12,12 @@ buildscript {
}
}

apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

apply from: 'config.gradle'

allprojects {
repositories {
Expand Down Expand Up @@ -79,6 +82,10 @@ android {
targetCompatibility versions.javaVersion
}

kotlinOptions {
jvmTarget = versions.javaVersion
}

assetPacks = [":assetPacks:installTime"]

defaultConfig {
Expand Down
5 changes: 3 additions & 2 deletions platform/android/java/app/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ ext.versions = [
minSdk : 19, // Also update 'platform/android/java/lib/AndroidManifest.xml#minSdkVersion' & 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
targetSdk : 30, // Also update 'platform/android/java/lib/AndroidManifest.xml#targetSdkVersion' & 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
buildTools : '30.0.3',
kotlinVersion : '1.6.10',
kotlinVersion : '1.6.21',
fragmentVersion : '1.3.6',
nexusPublishVersion: '1.1.0',
javaVersion : 11,
ndkVersion : '21.4.7075529' // Also update 'platform/android/detect.py#get_project_ndk_version()' when this is updated.

Expand All @@ -14,7 +15,7 @@ ext.versions = [
ext.libraries = [
androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin",
kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlinVersion",
kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlinVersion",
androidxFragment : "androidx.fragment:fragment:$versions.fragmentVersion",
]

Expand Down
13 changes: 13 additions & 0 deletions platform/android/java/app/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
// This is the root directory of the Godot custom build.
pluginManagement {
apply from: 'config.gradle'

plugins {
id 'com.android.application' version versions.androidGradlePlugin
id 'org.jetbrains.kotlin.android' version versions.kotlinVersion
}
repositories {
gradlePluginPortal()
google()
}
}

include ':assetPacks:installTime'
11 changes: 7 additions & 4 deletions platform/android/java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
apply plugin: 'io.github.gradle-nexus.publish-plugin'
apply from: 'app/config.gradle'
apply from: 'scripts/publish-root.gradle'

buildscript {
apply from: 'app/config.gradle'

Expand All @@ -17,6 +13,13 @@ buildscript {
}
}

plugins {
id 'io.github.gradle-nexus.publish-plugin'
}

apply from: 'app/config.gradle'
apply from: 'scripts/publish-root.gradle'

allprojects {
repositories {
google()
Expand Down
9 changes: 8 additions & 1 deletion platform/android/java/editor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Gradle build config for Godot Engine's Android port.
apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

dependencies {
implementation libraries.kotlinStdLib
Expand Down Expand Up @@ -29,6 +32,10 @@ android {
targetCompatibility versions.javaVersion
}

kotlinOptions {
jvmTarget = versions.javaVersion
}

buildTypes {
dev {
initWith debug
Expand Down
10 changes: 8 additions & 2 deletions platform/android/java/lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

ext {
PUBLISH_VERSION = getGodotPublishVersion()
Expand Down Expand Up @@ -34,6 +36,10 @@ android {
targetCompatibility versions.javaVersion
}

kotlinOptions {
jvmTarget = versions.javaVersion
}

buildTypes {
dev {
initWith debug
Expand Down
5 changes: 5 additions & 0 deletions platform/android/java/nativeSrcsConfigs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Non functional android library used to provide Android Studio editor support to the project.
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
Expand All @@ -18,6 +19,10 @@ android {
targetCompatibility versions.javaVersion
}

kotlinOptions {
jvmTarget = versions.javaVersion
}

packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
Expand Down
15 changes: 15 additions & 0 deletions platform/android/java/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// Configure the root project.
pluginManagement {
apply from: 'app/config.gradle'

plugins {
id 'com.android.application' version versions.androidGradlePlugin
id 'com.android.library' version versions.androidGradlePlugin
id 'org.jetbrains.kotlin.android' version versions.kotlinVersion
id 'io.github.gradle-nexus.publish-plugin' version versions.nexusPublishVersion
}
repositories {
gradlePluginPortal()
google()
}
}

rootProject.name = "Godot"

include ':app'
Expand Down