Godot Engine – Multi-platform 2D and 3D game engine
Fix the creation of the debug keystore after set up of the Java SDK
Fredia Huya-Kouadioeff4b35e9262
diff --git a/editor/export/android_sdk_manager.cpp b/editor/export/android_sdk_manager.cppindex 8415d9bcf05..3c6da795442 100644--- a/editor/export/android_sdk_manager.cpp+++ b/editor/export/android_sdk_manager.cpp@@ -497,6 +497,9 @@ void AndroidSDKManager::_java_sdk_installed() {EditorSettings::get_singleton()->set_setting("export/android/java_sdk_path", EditorPaths::get_singleton()->get_default_java_sdk_path());EditorSettings::get_singleton()->save();+ // Check if we need to create the debug keystore.+ create_editor_debug_keystore_if_needed();+_hide_setup_dialog(current_setup_status);emit_signal(SNAME("java_sdk_installed"));@@ -743,6 +746,18 @@ String AndroidSDKManager::get_android_cli_path() {return cli_path.path_join("android" + exe_ext);}+String AndroidSDKManager::_get_keytool_path(const String &p_java_sdk_path) {+ String exe_ext;+ if (OS::get_singleton()->get_name() == "Windows") {+ exe_ext = ".exe";+ }+ return p_java_sdk_path.path_join("bin/keytool" + exe_ext);+}++String AndroidSDKManager::get_keytool_path() {+ return _get_keytool_path(EDITOR_GET("export/android/java_sdk_path"));+}+String AndroidSDKManager::_get_java_path(const String &p_java_sdk_path) {String exe_ext;if (OS::get_singleton()->get_name() == "Windows") {@@ -888,6 +903,66 @@ String AndroidSDKManager::get_apksigner_path(int p_target_sdk, bool p_check_execreturn apksigner_path;}+void AndroidSDKManager::create_editor_debug_keystore_if_needed() {+ // Check if we have a valid keytool path.+ String keytool_path = get_keytool_path();+ if (!FileAccess::exists(keytool_path)) {+ return;+ }++ // Check if the current editor debug keystore exists.+ String editor_debug_keystore = EDITOR_GET("export/android/debug_keystore");+ if (FileAccess::exists(editor_debug_keystore)) {+ return;+ }++ // Generate the debug keystore.+ String keystore_path = EditorPaths::get_singleton()->get_debug_keystore_path();+ String keystores_dir = keystore_path.get_base_dir();+ if (!DirAccess::exists(keystores_dir)) {+ Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);+ Error err = dir_access->make_dir_recursive(keystores_dir);+ if (err != OK) {+ WARN_PRINT("Error creating keystores directory:\n" + keystores_dir);+ return;+ }+ }++ if (!FileAccess::exists(keystore_path)) {+ String output;+ List<String> args;+ args.push_back("-genkey");+ args.push_back("-keystore");+ args.push_back(keystore_path);+ args.push_back("-storepass");+ args.push_back("android");+ args.push_back("-alias");+ args.push_back(DEFAULT_ANDROID_KEYSTORE_DEBUG_USER);+ args.push_back("-keypass");+ args.push_back(DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD);+ args.push_back("-keyalg");+ args.push_back("RSA");+ args.push_back("-keysize");+ args.push_back("2048");+ args.push_back("-validity");+ args.push_back("10000");+ args.push_back("-dname");+ args.push_back("cn=Godot, ou=Godot Engine, o=Stichting Godot, c=NL");+ Error error = OS::get_singleton()->execute(keytool_path, args, &output, nullptr, true);+ print_verbose(output);+ if (error != OK) {+ WARN_PRINT("Error: Unable to create debug keystore");+ return;+ }+ }++ // Update the editor settings.+ EditorSettings::get_singleton()->set("export/android/debug_keystore", keystore_path);+ EditorSettings::get_singleton()->set("export/android/debug_keystore_user", DEFAULT_ANDROID_KEYSTORE_DEBUG_USER);+ EditorSettings::get_singleton()->set("export/android/debug_keystore_pass", DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD);+ print_verbose("Updated editor debug keystore to " + keystore_path);+}+AndroidSDKManager::AndroidSDKManager() {set_title(TTRC("Android SDK Manager"));add_cancel_button();diff --git a/editor/export/android_sdk_manager.h b/editor/export/android_sdk_manager.hindex 156438bb02e..34535575214 100644--- a/editor/export/android_sdk_manager.h+++ b/editor/export/android_sdk_manager.h@@ -37,6 +37,9 @@ class Label;class ProgressBar;class RichTextLabel;+const String DEFAULT_ANDROID_KEYSTORE_DEBUG_USER = "androiddebugkey";+const String DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD = "android";+class AndroidSDKManager : public AcceptDialog {GDCLASS(AndroidSDKManager, AcceptDialog)@@ -76,6 +79,7 @@ class AndroidSDKManager : public AcceptDialog {static bool _is_android_sdk_setup(const String &p_android_sdk_path, String *r_error = nullptr);static bool _is_java_sdk_setup(const String &p_java_sdk_path, String *r_error = nullptr);+ static String _get_keytool_path(const String &p_java_sdk_path);static String _get_java_path(const String &p_java_sdk_path);static String _get_adb_path(const String &p_android_sdk_path);@@ -108,9 +112,12 @@ public:/// Returns true if the Java SDK is set up.static bool is_java_sdk_setup(String *r_error = nullptr);+ static String get_keytool_path();static String get_java_path();static String get_adb_path();static String get_apksigner_path(int p_target_sdk = -1, bool p_check_executes = false);+ static void create_editor_debug_keystore_if_needed();+AndroidSDKManager();};diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cppindex 8c82a254735..5c38815756d 100644--- a/platform/android/export/export.cpp+++ b/platform/android/export/export.cpp@@ -34,6 +34,7 @@#include "core/object/class_db.h"#include "core/os/os.h"+#include "editor/export/android_sdk_manager.h"#include "editor/export/editor_export.h"#include "editor/file_system/editor_paths.h"#include "editor/settings/editor_settings.h"diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cppindex 47d9520995c..cb63eb9f7b7 100644--- a/platform/android/export/export_plugin.cpp+++ b/platform/android/export/export_plugin.cpp@@ -910,73 +910,13 @@ void EditorExportPlatformAndroid::_notification(int p_what) {case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {if (EditorSettings::get_singleton()->check_changed_settings_in_group("export/android")) {- _create_editor_debug_keystore_if_needed();+ AndroidSDKManager::create_editor_debug_keystore_if_needed();}} break;}#endif}-void EditorExportPlatformAndroid::_create_editor_debug_keystore_if_needed() {- // Check if we have a valid keytool path.- String keytool_path = get_keytool_path();- if (!FileAccess::exists(keytool_path)) {- return;- }-- // Check if the current editor debug keystore exists.- String editor_debug_keystore = EDITOR_GET("export/android/debug_keystore");- if (FileAccess::exists(editor_debug_keystore)) {- return;- }-- // Generate the debug keystore.- String keystore_path = EditorPaths::get_singleton()->get_debug_keystore_path();- String keystores_dir = keystore_path.get_base_dir();- if (!DirAccess::exists(keystores_dir)) {- Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);- Error err = dir_access->make_dir_recursive(keystores_dir);- if (err != OK) {- WARN_PRINT(TTR("Error creating keystores directory:") + "\n" + keystores_dir);- return;- }- }-- if (!FileAccess::exists(keystore_path)) {- String output;- List<String> args;- args.push_back("-genkey");- args.push_back("-keystore");- args.push_back(keystore_path);- args.push_back("-storepass");- args.push_back("android");- args.push_back("-alias");- args.push_back(DEFAULT_ANDROID_KEYSTORE_DEBUG_USER);- args.push_back("-keypass");- args.push_back(DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD);- args.push_back("-keyalg");- args.push_back("RSA");- args.push_back("-keysize");- args.push_back("2048");- args.push_back("-validity");- args.push_back("10000");- args.push_back("-dname");- args.push_back("cn=Godot, ou=Godot Engine, o=Stichting Godot, c=NL");- Error error = OS::get_singleton()->execute(keytool_path, args, &output, nullptr, true);- print_verbose(output);- if (error != OK) {- WARN_PRINT("Error: Unable to create debug keystore");- return;- }- }-- // Update the editor settings.- EditorSettings::get_singleton()->set("export/android/debug_keystore", keystore_path);- EditorSettings::get_singleton()->set("export/android/debug_keystore_user", DEFAULT_ANDROID_KEYSTORE_DEBUG_USER);- EditorSettings::get_singleton()->set("export/android/debug_keystore_pass", DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD);- print_verbose("Updated editor debug keystore to " + keystore_path);-}-void EditorExportPlatformAndroid::_get_manifest_info(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions, Vector<FeatureInfo> &r_features, Vector<MetadataInfo> &r_metadata) {const char **aperms = ANDROID_PERMS;while (*aperms) {@@ -2675,15 +2615,6 @@ Ref<Texture2D> EditorExportPlatformAndroid::get_run_icon() const {return run_icon;}-String EditorExportPlatformAndroid::get_keytool_path() {- String exe_ext;- if (OS::get_singleton()->get_name() == "Windows") {- exe_ext = ".exe";- }- String java_sdk_path = EDITOR_GET("export/android/java_sdk_path");- return java_sdk_path.path_join("bin/keytool" + exe_ext);-}-static bool has_valid_keystore_credentials(String &r_error_str, const String &p_keystore, const String &p_username, const String &p_password, const String &p_type) {String output;List<String> args;@@ -2694,7 +2625,7 @@ static bool has_valid_keystore_credentials(String &r_error_str, const String &p_args.push_back(p_password);args.push_back("-alias");args.push_back(p_username);- String keytool_path = EditorExportPlatformAndroid::get_keytool_path();+ String keytool_path = AndroidSDKManager::get_keytool_path();Error error = OS::get_singleton()->execute(keytool_path, args, &output, nullptr, true);String keytool_error = "keytool error:";bool valid = output.substr(0, keytool_error.length()) != keytool_error;@@ -2874,7 +2805,9 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Edito// Validate the rest of the export configuration.- if (p_debug) {+ // Validate the debug keystore setup.+ bool has_valid_debug_keystore = true;+ {String dk = _get_keystore_path(p_preset, true);String dk_user = p_preset->get_or_env("keystore/debug_user", ENV_ANDROID_KEYSTORE_DEBUG_USER);String dk_password = p_preset->get_or_env("keystore/debug_password", ENV_ANDROID_KEYSTORE_DEBUG_PASS);@@ -2884,15 +2817,22 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Editoerr += TTR("Either Debug Keystore, Debug User AND Debug Password settings must be configured OR none of them.") + "\n";}- // Use OR to make the export UI able to show this error.- if (!dk.is_empty() && !FileAccess::exists(dk)) {+ if (dk.is_empty()) {+ // Check the editor setting.dk = EDITOR_GET("export/android/debug_keystore");- if (!FileAccess::exists(dk)) {- valid = false;+ if (dk.is_empty() || !FileAccess::exists(dk)) {+ has_valid_debug_keystore = false;err += TTR("Debug keystore not configured in the Editor Settings nor in the preset.") + "\n";}+ } else if (!FileAccess::exists(dk)) {+ has_valid_debug_keystore = false;+ err += TTR("Debug keystore incorrectly configured in the export preset.") + "\n";}- } else {+ }++ // Validate the release keystore setup.+ bool has_valid_release_keystore = true;+ {String rk = _get_keystore_path(p_preset, false);String rk_user = p_preset->get_or_env("keystore/release_user", ENV_ANDROID_KEYSTORE_RELEASE_USER);String rk_password = p_preset->get_or_env("keystore/release_password", ENV_ANDROID_KEYSTORE_RELEASE_PASS);@@ -2902,12 +2842,19 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Editoerr += TTR("Either Release Keystore, Release User AND Release Password settings must be configured OR none of them.") + "\n";}- if (!rk.is_empty() && !FileAccess::exists(rk)) {- valid = false;+ if (rk.is_empty()) {+ has_valid_release_keystore = false;+ } else if (!FileAccess::exists(rk)) {+ has_valid_release_keystore = false;err += TTR("Release keystore incorrectly configured in the export preset.") + "\n";}}+ // If both keystores are not configured, then it's an error.+ if (!has_valid_debug_keystore && !has_valid_release_keystore) {+ valid = false;+ }+#ifndef ANDROID_ENABLEDif (!AndroidSDKManager::is_java_sdk_setup(&err)) {valid = false;@@ -4277,7 +4224,7 @@ void EditorExportPlatformAndroid::initialize() {#endif // DISABLE_DEPRECATED#ifndef ANDROID_ENABLEDdevices_changed.set();- _create_editor_debug_keystore_if_needed();+ AndroidSDKManager::create_editor_debug_keystore_if_needed();_update_preset_status();use_scrcpy = EditorSettings::get_singleton()->get_project_metadata("android", "use_scrcpy", false);#else // ANDROID_ENABLEDdiff --git a/platform/android/export/export_plugin.h b/platform/android/export/export_plugin.hindex 69324a769ee..72b2a1910df 100644--- a/platform/android/export/export_plugin.h+++ b/platform/android/export/export_plugin.h@@ -51,9 +51,6 @@ const String ENV_ANDROID_KEYSTORE_RELEASE_PATH = "GODOT_ANDROID_KEYSTORE_RELEASEconst String ENV_ANDROID_KEYSTORE_RELEASE_USER = "GODOT_ANDROID_KEYSTORE_RELEASE_USER";const String ENV_ANDROID_KEYSTORE_RELEASE_PASS = "GODOT_ANDROID_KEYSTORE_RELEASE_PASSWORD";-const String DEFAULT_ANDROID_KEYSTORE_DEBUG_USER = "androiddebugkey";-const String DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD = "android";-struct LauncherIcon {const char *export_path;int dimensions = 0;@@ -197,8 +194,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {const Ref<Image> &p_splash_icon,const Ref<Image> &p_splash_branding_image);- static void _create_editor_debug_keystore_if_needed();-static Vector<ABI> get_enabled_abis(const Ref<EditorExportPreset> &p_preset);bool _uses_vulkan(const Ref<EditorExportPreset> &p_preset) const;@@ -247,8 +242,6 @@ public:virtual Ref<Texture2D> get_run_icon() const override;- static String get_keytool_path();-virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;static bool has_valid_username_and_password(const Ref<EditorExportPreset> &p_preset, String &r_error);