Skip to content

Commit

Permalink
Update Android dependencies for the project
Browse files Browse the repository at this point in the history
- Update Java version from 11 to 17
- Update Android gradle plugin version from 7.2.1 to 8.2.0
- Update gradle version from 7.4.2 to 8.2
- Update target SDK from 33 to 34
- Update build tools version from 33.0.2 to 34.0.0
- Update kotlin version from 1.7.0 to 1.9.20
- Update Android fragment version from 1.3.6 to 1.6.2
- Update AndroidX window version from 1.0.0 to 1.2.0
- Update Nexus plugin version from 1.1.0 to 1.3.0
  • Loading branch information
m4gr3d committed Jan 25, 2024
1 parent 584dc09 commit eba77be
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
sudo apt-get update
- name: Set up Java 11
- name: Set up Java 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
java-version: 17

- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
Expand Down
2 changes: 2 additions & 0 deletions platform/android/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

void register_android_exporter() {
#ifndef ANDROID_ENABLED
EDITOR_DEF("export/android/java_sdk_path", OS::get_singleton()->get_environment("JAVA_HOME"));
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/java_sdk_path", PROPERTY_HINT_GLOBAL_DIR));
EDITOR_DEF("export/android/android_sdk_path", OS::get_singleton()->get_environment("ANDROID_SDK_ROOT"));
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/android_sdk_path", PROPERTY_HINT_GLOBAL_DIR));
EDITOR_DEF("export/android/debug_keystore", "");
Expand Down
47 changes: 45 additions & 2 deletions platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static const char *APK_ASSETS_DIRECTORY = "res://android/build/assets";
static const char *AAB_ASSETS_DIRECTORY = "res://android/build/assetPacks/installTime/src/main/assets";

static const int DEFAULT_MIN_SDK_VERSION = 19; // Should match the value in 'platform/android/java/app/config.gradle#minSdk'
static const int DEFAULT_TARGET_SDK_VERSION = 33; // Should match the value in 'platform/android/java/app/config.gradle#targetSdk'
static const int DEFAULT_TARGET_SDK_VERSION = 34; // Should match the value in 'platform/android/java/app/config.gradle#targetSdk'

#ifndef ANDROID_ENABLED
void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
Expand Down Expand Up @@ -2012,6 +2012,15 @@ Ref<Texture> EditorExportPlatformAndroid::get_run_icon() const {
return run_icon;
}

String EditorExportPlatformAndroid::get_java_path() {
String exe_ext = "";
if (OS::get_singleton()->get_name() == "Windows") {
exe_ext = ".exe";
}
String java_sdk_path = EditorSettings::get_singleton()->get("export/android/java_sdk_path");
return java_sdk_path.plus_file("bin/java" + exe_ext);
}

String EditorExportPlatformAndroid::get_adb_path() {
String exe_ext = "";
if (OS::get_singleton()->get_name() == "Windows") {
Expand Down Expand Up @@ -2142,6 +2151,32 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Edito
err += TTR("Release keystore incorrectly configured in the export preset.") + "\n";
}

String java_sdk_path = EditorSettings::get_singleton()->get("export/android/java_sdk_path");
if (java_sdk_path == "") {
err += TTR("A valid Java SDK path is required in Editor Settings.") + "\n";
valid = false;
} else {
// Validate the given path by checking that `java` is present under the `bin` directory.
Error errn;
// Check for the bin directory.
DirAccessRef da = DirAccess::open(java_sdk_path.plus_file("bin"), &errn);
if (errn != OK) {
err += TTR("Invalid Java SDK path in Editor Settings.");
err += TTR("Missing 'bin' directory!");
err += "\n";
valid = false;
} else {
// Check for the `java` command.
String java_path = get_java_path();
if (!FileAccess::exists(java_path)) {
err += TTR("Unable to find 'java' command using the Java SDK path.");
err += TTR("Please check the Java SDK directory specified in Editor Settings.");
err += "\n";
valid = false;
}
}
}

String sdk_path = EditorSettings::get_singleton()->get("export/android/android_sdk_path");
if (sdk_path == "") {
err += TTR("A valid Android SDK path is required in Editor Settings.") + "\n";
Expand Down Expand Up @@ -2931,6 +2966,10 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
}
}
const String assets_directory = get_assets_directory(p_preset, export_format);
String java_sdk_path = EDITOR_GET("export/android/java_sdk_path");
ERR_FAIL_COND_V_MSG(java_sdk_path.empty(), ERR_UNCONFIGURED, "Java SDK path must be configured in Editor Settings at 'export/android/java_sdk_path'.");
print_verbose("Java sdk path: " + java_sdk_path);

String sdk_path = EDITOR_GET("export/android/android_sdk_path");
ERR_FAIL_COND_V_MSG(sdk_path.empty(), ERR_UNCONFIGURED, "Android SDK path must be configured in Editor Settings at 'export/android/android_sdk_path'.");
print_verbose("Android sdk path: " + sdk_path);
Expand Down Expand Up @@ -2975,8 +3014,11 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
print_verbose("Storing command line flags..");
store_file_at_path(assets_directory + "/_cl_", command_line_flags);

print_verbose("Updating JAVA_HOME environment to " + java_sdk_path);
OS::get_singleton()->set_environment("JAVA_HOME", java_sdk_path);

print_verbose("Updating ANDROID_HOME environment to " + sdk_path);
OS::get_singleton()->set_environment("ANDROID_HOME", sdk_path); //set and overwrite if required
OS::get_singleton()->set_environment("ANDROID_HOME", sdk_path);
String build_command;

#ifdef WINDOWS_ENABLED
Expand Down Expand Up @@ -3010,6 +3052,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
bool clean_build_required = is_clean_build_required(enabled_plugins);

List<String> cmdline;
cmdline.push_back("validateJavaVersion");
if (clean_build_required) {
cmdline.push_back("clean");
}
Expand Down
2 changes: 2 additions & 0 deletions platform/android/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

static String get_apksigner_path();

static String get_java_path();

virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;

Expand Down
1 change: 0 additions & 1 deletion platform/android/java/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.godot.game"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto" >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.asset-pack'
plugins {
id 'com.android.asset-pack'
}

assetPack {
packName = "installTime" // Directory name for the asset pack
Expand Down
36 changes: 32 additions & 4 deletions platform/android/java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven { url "https://plugins.gradle.org/m2/" }
//CHUNK_BUILDSCRIPT_REPOSITORIES_BEGIN
//CHUNK_BUILDSCRIPT_REPOSITORIES_END
}
dependencies {
classpath libraries.androidGradlePlugin
classpath libraries.kotlinGradlePlugin
classpath "com.android.tools.build:gradle:$versions.androidGradlePlugin"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion"
//CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
//CHUNK_BUILDSCRIPT_DEPENDENCIES_END
}
Expand All @@ -30,6 +32,8 @@ allprojects {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven { url "https://plugins.gradle.org/m2/" }
//CHUNK_ALLPROJECTS_REPOSITORIES_BEGIN
//CHUNK_ALLPROJECTS_REPOSITORIES_END

Expand All @@ -51,8 +55,7 @@ configurations {
}

dependencies {
implementation libraries.kotlinStdLib
implementation libraries.androidxFragment
implementation "androidx.fragment:fragment:$versions.fragmentVersion"

if (rootProject.findProject(":lib")) {
implementation project(":lib")
Expand Down Expand Up @@ -100,6 +103,8 @@ android {

assetPacks = [":assetPacks:installTime"]

namespace = 'com.godot.game'

defaultConfig {
// The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Godot projects.
aaptOptions {
Expand Down Expand Up @@ -284,5 +289,28 @@ task copyAndRenameReleaseAab(type: Copy) {
rename "build-release.aab", getExportFilename()
}

/**
* Used to validate the version of the Java SDK used for the Godot gradle builds.
*/
task validateJavaVersion {
if (JavaVersion.current() != versions.javaVersion) {
throw new GradleException("Invalid Java version ${JavaVersion.current()}. Version ${versions.javaVersion} is the required Java version for Godot gradle builds.")
}
}

/*
When they're scheduled to run, the copy*AARToAppModule tasks generate dependencies for the 'app'
module, so we're ensuring the ':app:preBuild' task is set to run after those tasks.
*/
if (rootProject.tasks.findByPath("copyDebugAARToAppModule") != null) {
preBuild.mustRunAfter(rootProject.tasks.named("copyDebugAARToAppModule"))
}
if (rootProject.tasks.findByPath("copyDevAARToAppModule") != null) {
preBuild.mustRunAfter(rootProject.tasks.named("copyDevAARToAppModule"))
}
if (rootProject.tasks.findByPath("copyReleaseAARToAppModule") != null) {
preBuild.mustRunAfter(rootProject.tasks.named("copyReleaseAARToAppModule"))
}

//CHUNK_GLOBAL_BEGIN
//CHUNK_GLOBAL_END
23 changes: 8 additions & 15 deletions platform/android/java/app/config.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
ext.versions = [
androidGradlePlugin: '7.2.1',
compileSdk : 33,
androidGradlePlugin: '8.2.0',
compileSdk : 34,
minSdk : 19, // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
targetSdk : 33, // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
buildTools : '33.0.2',
kotlinVersion : '1.7.0',
fragmentVersion : '1.3.6',
nexusPublishVersion: '1.1.0',
javaVersion : 11,
targetSdk : 34, // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
buildTools : '34.0.0',
kotlinVersion : '1.9.20',
fragmentVersion : '1.6.2',
nexusPublishVersion: '1.3.0',
javaVersion : JavaVersion.VERSION_17,
ndkVersion : '23.2.8568313' // Also update 'platform/android/detect.py#get_ndk_version' when this is updated.

]

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:$versions.kotlinVersion",
androidxFragment : "androidx.fragment:fragment:$versions.fragmentVersion",
]

ext.getExportPackageName = { ->
// Retrieve the app id from the project property set by the Godot build command.
String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
Expand Down
4 changes: 3 additions & 1 deletion platform/android/java/app/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ pluginManagement {
id 'org.jetbrains.kotlin.android' version versions.kotlinVersion
}
repositories {
gradlePluginPortal()
google()
mavenCentral()
gradlePluginPortal()
maven { url "https://plugins.gradle.org/m2/" }
}
}

Expand Down
Loading

0 comments on commit eba77be

Please sign in to comment.