Skip to content

Commit

Permalink
Backported 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
- m4gr3d
godotengine/godot@eba77be
Unfortunately this raises the required java version to 17. On the flip side hovewer there is a new editor java home setting, and also the JAVA_HOME environment variable gets picked up.
  • Loading branch information
Relintai committed Apr 20, 2024
1 parent d6af267 commit 914c956
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 110 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,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 Pandemonium build cache
uses: ./.github/actions/pandemonium-cache
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/android_editor_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,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 Pandemonium build cache
uses: ./.github/actions/pandemonium-cache
Expand Down
8 changes: 0 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,6 @@ This PR mainly is to aid in faster development as outlined in godotengine/godot-

https://github.com/godotengine/godot/pull/52566

## [3.x] Update Android dependencies for the project

Updates Java version from 11 to 17. Will need more testing, also likely an udpate to my build containers.\
Do after the next release.

https://github.com/godotengine/godot/commit/d1b6b6f725af4fadb8108c3769d3e7a36f6f8e5a
https://github.com/godotengine/godot/pull/87588

## Cleanup TODOs

Cleanup this file, lots of things are already done.
Expand Down
7 changes: 2 additions & 5 deletions platform/android/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@

void register_android_exporter() {
#ifndef ANDROID_ENABLED
String exe_ext;
if (OS::get_singleton()->get_name() == "Windows") {
exe_ext = "*.exe";
}

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
48 changes: 46 additions & 2 deletions platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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'
const String SDK_VERSION_RANGE = vformat("%s,%s,1", DEFAULT_MIN_SDK_VERSION, DEFAULT_TARGET_SDK_VERSION);

#ifndef ANDROID_ENABLED
Expand Down Expand Up @@ -1939,6 +1939,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 @@ -2069,6 +2078,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 @@ -2804,6 +2839,11 @@ 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 @@ -2848,8 +2888,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 @@ -2877,6 +2920,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 @@ -205,6 +205,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.pandemonium.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.pandemonium.game'

defaultConfig {
// The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Pandemonium 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
24 changes: 8 additions & 16 deletions platform/android/java/app/config.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
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 = { ->
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 914c956

Please sign in to comment.