2021-07-13 20:30:53 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* export_plugin.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2022-05-30 21:13:49 +00:00
|
|
|
#ifndef ANDROID_EXPORT_PLUGIN_H
|
|
|
|
#define ANDROID_EXPORT_PLUGIN_H
|
|
|
|
|
2023-07-02 18:14:29 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2022-02-14 13:00:03 +00:00
|
|
|
#include "godot_plugin_config.h"
|
2023-07-02 18:14:29 +00:00
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-02-14 13:00:03 +00:00
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
#include "core/io/zip_io.h"
|
|
|
|
#include "core/os/os.h"
|
2022-07-17 17:24:37 +00:00
|
|
|
#include "editor/export/editor_export_platform.h"
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
const String SPLASH_CONFIG_XML_CONTENT = R"SPLASH(<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
|
|
<item android:drawable="@drawable/splash_bg_color" />
|
|
|
|
<item>
|
|
|
|
<bitmap
|
|
|
|
android:gravity="center"
|
|
|
|
android:filter="%s"
|
|
|
|
android:src="@drawable/splash" />
|
|
|
|
</item>
|
|
|
|
</layer-list>
|
|
|
|
)SPLASH";
|
|
|
|
|
2023-05-10 09:40:17 +00:00
|
|
|
// Optional environment variables for defining confidential information. If any
|
|
|
|
// of these is set, they will override the values set in the credentials file.
|
|
|
|
const String ENV_ANDROID_KEYSTORE_DEBUG_PATH = "GODOT_ANDROID_KEYSTORE_DEBUG_PATH";
|
|
|
|
const String ENV_ANDROID_KEYSTORE_DEBUG_USER = "GODOT_ANDROID_KEYSTORE_DEBUG_USER";
|
|
|
|
const String ENV_ANDROID_KEYSTORE_DEBUG_PASS = "GODOT_ANDROID_KEYSTORE_DEBUG_PASSWORD";
|
|
|
|
const String ENV_ANDROID_KEYSTORE_RELEASE_PATH = "GODOT_ANDROID_KEYSTORE_RELEASE_PATH";
|
|
|
|
const String ENV_ANDROID_KEYSTORE_RELEASE_USER = "GODOT_ANDROID_KEYSTORE_RELEASE_USER";
|
|
|
|
const String ENV_ANDROID_KEYSTORE_RELEASE_PASS = "GODOT_ANDROID_KEYSTORE_RELEASE_PASSWORD";
|
|
|
|
|
2024-04-13 06:53:28 +00:00
|
|
|
const String DEFAULT_ANDROID_KEYSTORE_DEBUG_USER = "androiddebugkey";
|
|
|
|
const String DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD = "android";
|
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
struct LauncherIcon {
|
|
|
|
const char *export_path;
|
|
|
|
int dimensions = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EditorExportPlatformAndroid : public EditorExportPlatform {
|
|
|
|
GDCLASS(EditorExportPlatformAndroid, EditorExportPlatform);
|
|
|
|
|
|
|
|
Ref<ImageTexture> logo;
|
|
|
|
Ref<ImageTexture> run_icon;
|
|
|
|
|
|
|
|
struct Device {
|
|
|
|
String id;
|
|
|
|
String name;
|
|
|
|
String description;
|
|
|
|
int api_level = 0;
|
2024-02-20 23:01:33 +00:00
|
|
|
String architecture;
|
2021-07-13 20:30:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct APKExportData {
|
|
|
|
zipFile apk;
|
|
|
|
EditorProgress *ep = nullptr;
|
|
|
|
};
|
|
|
|
|
2023-07-02 18:14:29 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
mutable Vector<PluginConfigAndroid> android_plugins;
|
|
|
|
mutable SafeFlag android_plugins_changed;
|
|
|
|
Mutex android_plugins_lock;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2021-07-13 20:30:53 +00:00
|
|
|
String last_plugin_names;
|
2023-02-01 23:17:06 +00:00
|
|
|
uint64_t last_gradle_build_time = 0;
|
2024-02-13 20:20:23 +00:00
|
|
|
String last_gradle_build_dir;
|
2023-07-02 18:14:29 +00:00
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
Vector<Device> devices;
|
|
|
|
SafeFlag devices_changed;
|
|
|
|
Mutex device_lock;
|
2022-08-15 09:30:43 +00:00
|
|
|
#ifndef ANDROID_ENABLED
|
2021-07-13 20:30:53 +00:00
|
|
|
Thread check_for_changes_thread;
|
|
|
|
SafeFlag quit_request;
|
2024-02-01 15:02:39 +00:00
|
|
|
SafeFlag has_runnable_preset;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
static void _check_for_changes_poll_thread(void *ud);
|
2024-02-01 15:02:39 +00:00
|
|
|
void _update_preset_status();
|
2022-08-15 09:30:43 +00:00
|
|
|
#endif
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
String get_project_name(const String &p_name) const;
|
|
|
|
|
|
|
|
String get_package_name(const String &p_package) const;
|
|
|
|
|
2023-01-18 18:56:52 +00:00
|
|
|
String get_valid_basename() const;
|
|
|
|
|
2021-10-11 15:02:03 +00:00
|
|
|
String get_assets_directory(const Ref<EditorExportPreset> &p_preset, int p_export_format) const;
|
2021-09-10 02:55:42 +00:00
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const;
|
2023-01-18 18:56:52 +00:00
|
|
|
bool is_project_name_valid() const;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
|
|
|
|
|
|
|
|
static zip_fileinfo get_zip_fileinfo();
|
|
|
|
|
2022-11-07 10:56:20 +00:00
|
|
|
struct ABI {
|
|
|
|
String abi;
|
|
|
|
String arch;
|
|
|
|
|
|
|
|
bool operator==(const ABI &p_a) const {
|
|
|
|
return p_a.abi == abi;
|
|
|
|
}
|
|
|
|
|
|
|
|
ABI(const String &p_abi, const String &p_arch) {
|
|
|
|
abi = p_abi;
|
|
|
|
arch = p_arch;
|
|
|
|
}
|
|
|
|
ABI() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
static Vector<ABI> get_abis();
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2023-07-02 18:14:29 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2021-07-13 20:30:53 +00:00
|
|
|
/// List the gdap files in the directory specified by the p_path parameter.
|
|
|
|
static Vector<String> list_gdap_files(const String &p_path);
|
|
|
|
|
|
|
|
static Vector<PluginConfigAndroid> get_plugins();
|
|
|
|
|
|
|
|
static Vector<PluginConfigAndroid> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets);
|
2023-07-02 18:14:29 +00:00
|
|
|
#endif // DISABLE_DEPRECATED
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
static Error store_in_apk(APKExportData *ed, const String &p_path, const Vector<uint8_t> &p_data, int compression_method = Z_DEFLATED);
|
|
|
|
|
|
|
|
static Error save_apk_so(void *p_userdata, const SharedObject &p_so);
|
|
|
|
|
|
|
|
static Error save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
|
|
|
|
|
|
|
static Error ignore_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
|
|
|
|
|
|
|
static Error copy_gradle_so(void *p_userdata, const SharedObject &p_so);
|
|
|
|
|
2021-07-11 01:39:31 +00:00
|
|
|
bool _has_read_write_storage_permission(const Vector<String> &p_permissions);
|
|
|
|
|
|
|
|
bool _has_manage_external_storage_permission(const Vector<String> &p_permissions);
|
2021-07-11 01:39:31 +00:00
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
void _get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions);
|
|
|
|
|
|
|
|
void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug);
|
|
|
|
|
|
|
|
void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet);
|
|
|
|
|
2024-04-13 00:00:09 +00:00
|
|
|
static String _get_keystore_path(const Ref<EditorExportPreset> &p_preset, bool p_debug);
|
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
static String _parse_string(const uint8_t *p_bytes, bool p_utf8);
|
|
|
|
|
|
|
|
void _fix_resources(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &r_manifest);
|
|
|
|
|
|
|
|
void _load_image_data(const Ref<Image> &p_splash_image, Vector<uint8_t> &p_data);
|
|
|
|
|
|
|
|
void _process_launcher_icons(const String &p_file_name, const Ref<Image> &p_source_image, int dimension, Vector<uint8_t> &p_data);
|
|
|
|
|
|
|
|
String load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image);
|
|
|
|
|
|
|
|
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background);
|
|
|
|
|
|
|
|
void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
|
|
|
|
const String &processed_splash_config_xml,
|
|
|
|
const Ref<Image> &splash_image,
|
|
|
|
const Ref<Image> &splash_bg_color_image,
|
|
|
|
const Ref<Image> &main_image,
|
|
|
|
const Ref<Image> &foreground,
|
|
|
|
const Ref<Image> &background);
|
|
|
|
|
2024-04-13 06:53:28 +00:00
|
|
|
static void _create_editor_debug_keystore_if_needed();
|
|
|
|
|
2022-11-07 10:56:20 +00:00
|
|
|
static Vector<ABI> get_enabled_abis(const Ref<EditorExportPreset> &p_preset);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2023-02-06 18:09:25 +00:00
|
|
|
static bool _uses_vulkan();
|
|
|
|
|
2024-02-01 15:02:39 +00:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
public:
|
|
|
|
typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
|
|
|
|
|
2022-07-27 22:34:12 +00:00
|
|
|
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2023-03-09 08:41:52 +00:00
|
|
|
virtual void get_export_options(List<ExportOption> *r_options) const override;
|
|
|
|
|
2024-02-13 20:20:23 +00:00
|
|
|
virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;
|
|
|
|
|
2023-03-09 08:41:52 +00:00
|
|
|
virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const override;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
virtual String get_name() const override;
|
|
|
|
|
|
|
|
virtual String get_os_name() const override;
|
|
|
|
|
|
|
|
virtual Ref<Texture2D> get_logo() const override;
|
|
|
|
|
|
|
|
virtual bool should_update_export_options() override;
|
|
|
|
|
|
|
|
virtual bool poll_export() override;
|
|
|
|
|
|
|
|
virtual int get_options_count() const override;
|
|
|
|
|
|
|
|
virtual String get_options_tooltip() const override;
|
|
|
|
|
|
|
|
virtual String get_option_label(int p_index) const override;
|
|
|
|
|
|
|
|
virtual String get_option_tooltip(int p_index) const override;
|
|
|
|
|
2024-02-20 23:01:33 +00:00
|
|
|
virtual String get_device_architecture(int p_index) const override;
|
|
|
|
|
2021-07-13 20:30:53 +00:00
|
|
|
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) override;
|
|
|
|
|
|
|
|
virtual Ref<Texture2D> get_run_icon() const override;
|
|
|
|
|
|
|
|
static String get_adb_path();
|
|
|
|
|
2022-10-20 09:37:02 +00:00
|
|
|
static String get_apksigner_path(int p_target_sdk = -1, bool p_check_executes = false);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2023-12-21 08:13:16 +00:00
|
|
|
static String get_java_path();
|
|
|
|
|
2024-04-13 06:53:28 +00:00
|
|
|
static String get_keytool_path();
|
|
|
|
|
2023-06-11 17:01:39 +00:00
|
|
|
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;
|
2022-07-17 19:26:03 +00:00
|
|
|
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
|
2023-10-19 04:49:05 +00:00
|
|
|
static bool has_valid_username_and_password(const Ref<EditorExportPreset> &p_preset, String &r_error);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
|
|
|
|
|
2023-07-02 18:14:29 +00:00
|
|
|
String _get_plugins_names(const Ref<EditorExportPreset> &p_preset) const;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2023-07-02 18:14:29 +00:00
|
|
|
String _resolve_export_plugin_android_library_path(const String &p_android_library_path) const;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2023-07-02 18:14:29 +00:00
|
|
|
bool _is_clean_build_required(const Ref<EditorExportPreset> &p_preset);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
String get_apk_expansion_fullpath(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
|
|
|
|
2022-03-10 07:48:25 +00:00
|
|
|
Error save_apk_expansion_file(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
void get_command_line_flags(const Ref<EditorExportPreset> &p_preset, const String &p_path, int p_flags, Vector<uint8_t> &r_command_line_flags);
|
|
|
|
|
|
|
|
Error sign_apk(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &export_path, EditorProgress &ep);
|
|
|
|
|
2024-02-13 20:20:23 +00:00
|
|
|
void _clear_assets_directory(const Ref<EditorExportPreset> &p_preset);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2024-02-13 20:20:23 +00:00
|
|
|
void _remove_copied_libs(String p_gdextension_libs_path);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2022-11-07 10:56:20 +00:00
|
|
|
static String join_list(const List<String> &p_parts, const String &p_separator);
|
|
|
|
static String join_abis(const Vector<ABI> &p_parts, const String &p_separator, bool p_use_arch);
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
|
|
|
|
|
|
|
|
Error export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int export_format, bool should_sign, int p_flags);
|
|
|
|
|
2022-07-27 22:34:12 +00:00
|
|
|
virtual void get_platform_features(List<String> *r_features) const override;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
2022-05-19 15:00:06 +00:00
|
|
|
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override;
|
2021-07-13 20:30:53 +00:00
|
|
|
|
|
|
|
EditorExportPlatformAndroid();
|
|
|
|
|
|
|
|
~EditorExportPlatformAndroid();
|
|
|
|
};
|
2022-05-30 21:13:49 +00:00
|
|
|
|
|
|
|
#endif // ANDROID_EXPORT_PLUGIN_H
|