Merge pull request #52515 from m4gr3d/android_export_refactoring
[3.x] Refactor Android platform export structure
This commit is contained in:
commit
815c16ae17
8 changed files with 3967 additions and 3654 deletions
|
@ -32,7 +32,10 @@ if env["tools"]:
|
|||
reg_exporters_inc = '#include "register_exporters.h"\n'
|
||||
reg_exporters = "void register_exporters() {\n"
|
||||
for e in env.platform_exporters:
|
||||
env.add_source_files(env.editor_sources, "#platform/" + e + "/export/export.cpp")
|
||||
# Glob all .cpp files in export folder
|
||||
files = Glob("#platform/" + e + "/export/" + "*.cpp")
|
||||
env.add_source_files(env.editor_sources, files)
|
||||
|
||||
reg_exporters += "\tregister_" + e + "_exporter();\n"
|
||||
reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n'
|
||||
reg_exporters += "}\n"
|
||||
|
|
File diff suppressed because it is too large
Load diff
3295
platform/android/export/export_plugin.cpp
Normal file
3295
platform/android/export/export_plugin.cpp
Normal file
File diff suppressed because it is too large
Load diff
259
platform/android/export/export_plugin.h
Normal file
259
platform/android/export/export_plugin.h
Normal file
|
@ -0,0 +1,259 @@
|
|||
/*************************************************************************/
|
||||
/* export_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/json.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/os/dir_access.h"
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "core/safe_refcount.h"
|
||||
#include "core/version.h"
|
||||
#include "drivers/png/png_driver_common.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_log.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "main/splash.gen.h"
|
||||
#include "platform/android/logo.gen.h"
|
||||
#include "platform/android/run_icon.gen.h"
|
||||
|
||||
#include "godot_plugin_config.h"
|
||||
#include "gradle_export_util.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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";
|
||||
|
||||
struct LauncherIcon {
|
||||
const char *export_path;
|
||||
int dimensions;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
struct APKExportData {
|
||||
zipFile apk;
|
||||
EditorProgress *ep;
|
||||
};
|
||||
|
||||
struct CustomExportData {
|
||||
bool debug;
|
||||
Vector<String> libs;
|
||||
};
|
||||
|
||||
Vector<PluginConfigAndroid> plugins;
|
||||
String last_plugin_names;
|
||||
uint64_t last_custom_build_time = 0;
|
||||
SafeFlag plugins_changed;
|
||||
Mutex plugins_lock;
|
||||
Vector<Device> devices;
|
||||
SafeFlag devices_changed;
|
||||
Mutex device_lock;
|
||||
Thread check_for_changes_thread;
|
||||
SafeFlag quit_request;
|
||||
|
||||
static void _check_for_changes_poll_thread(void *ud);
|
||||
|
||||
String get_project_name(const String &p_name) const;
|
||||
|
||||
String get_package_name(const String &p_package) const;
|
||||
|
||||
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const;
|
||||
|
||||
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
|
||||
|
||||
static zip_fileinfo get_zip_fileinfo();
|
||||
|
||||
static Vector<String> get_abis();
|
||||
|
||||
/// 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);
|
||||
|
||||
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);
|
||||
|
||||
static Error ignore_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
|
||||
|
||||
static Error copy_gradle_so(void *p_userdata, const SharedObject &p_so);
|
||||
|
||||
bool _has_storage_permission(const Vector<String> &p_permissions);
|
||||
|
||||
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);
|
||||
|
||||
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 store_image(const LauncherIcon launcher_icon, const Vector<uint8_t> &data);
|
||||
|
||||
void store_image(const String &export_path, const Vector<uint8_t> &data);
|
||||
|
||||
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);
|
||||
|
||||
static Vector<String> get_enabled_abis(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
public:
|
||||
typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
|
||||
|
||||
public:
|
||||
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
|
||||
|
||||
virtual void get_export_options(List<ExportOption> *r_options);
|
||||
|
||||
virtual String get_name() const;
|
||||
|
||||
virtual String get_os_name() const;
|
||||
|
||||
virtual Ref<Texture> get_logo() const;
|
||||
|
||||
virtual bool should_update_export_options();
|
||||
|
||||
virtual bool poll_export();
|
||||
|
||||
virtual int get_options_count() const;
|
||||
|
||||
virtual String get_options_tooltip() const;
|
||||
|
||||
virtual String get_option_label(int p_index) const;
|
||||
|
||||
virtual String get_option_tooltip(int p_index) const;
|
||||
|
||||
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags);
|
||||
|
||||
virtual Ref<Texture> get_run_icon() const;
|
||||
|
||||
static String get_adb_path();
|
||||
|
||||
static String get_apksigner_path();
|
||||
|
||||
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
|
||||
|
||||
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
|
||||
|
||||
void _update_custom_build_project();
|
||||
|
||||
inline bool is_clean_build_required(Vector<PluginConfigAndroid> enabled_plugins) {
|
||||
String plugin_names = PluginConfigAndroid::get_plugins_names(enabled_plugins);
|
||||
bool first_build = last_custom_build_time == 0;
|
||||
bool have_plugins_changed = false;
|
||||
|
||||
if (!first_build) {
|
||||
have_plugins_changed = plugin_names != last_plugin_names;
|
||||
if (!have_plugins_changed) {
|
||||
for (int i = 0; i < enabled_plugins.size(); i++) {
|
||||
if (enabled_plugins.get(i).last_updated > last_custom_build_time) {
|
||||
have_plugins_changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_custom_build_time = OS::get_singleton()->get_unix_time();
|
||||
last_plugin_names = plugin_names;
|
||||
|
||||
return have_plugins_changed || first_build;
|
||||
}
|
||||
|
||||
String get_apk_expansion_fullpath(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
|
||||
Error save_apk_expansion_file(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||
|
||||
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);
|
||||
|
||||
void _clear_assets_directory();
|
||||
|
||||
void _remove_copied_libs();
|
||||
|
||||
String join_list(List<String> parts, const String &separator) const;
|
||||
|
||||
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
|
||||
|
||||
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);
|
||||
|
||||
virtual void get_platform_features(List<String> *r_features);
|
||||
|
||||
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features);
|
||||
|
||||
EditorExportPlatformAndroid();
|
||||
|
||||
~EditorExportPlatformAndroid();
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* godot_plugin_config.h */
|
||||
/* godot_plugin_config.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
@ -28,61 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef GODOT_PLUGIN_CONFIG_H
|
||||
#define GODOT_PLUGIN_CONFIG_H
|
||||
|
||||
#include "core/error_list.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
/*
|
||||
The `config` section and fields are required and defined as follow:
|
||||
- **name**: name of the plugin.
|
||||
- **binary_type**: can be either `local` or `remote`. The type affects the **binary** field.
|
||||
- **binary**:
|
||||
- if **binary_type** is `local`, then this should be the filename of the plugin `aar` file in the `res://android/plugins` directory (e.g: `MyPlugin.aar`).
|
||||
- if **binary_type** is `remote`, then this should be a declaration for a remote gradle binary (e.g: "org.godot.example:my-plugin:0.0.0").
|
||||
|
||||
The `dependencies` section and fields are optional and defined as follow:
|
||||
- **local**: contains a list of local `.aar` binary files the plugin depends on. The local binary dependencies must also be located in the `res://android/plugins` directory.
|
||||
- **remote**: contains a list of remote binary gradle dependencies for the plugin.
|
||||
- **custom_maven_repos**: contains a list of urls specifying custom maven repos required for the plugin's dependencies.
|
||||
|
||||
See https://github.com/godotengine/godot/issues/38157#issuecomment-618773871
|
||||
*/
|
||||
struct PluginConfigAndroid {
|
||||
static const char *PLUGIN_CONFIG_EXT;
|
||||
|
||||
static const char *CONFIG_SECTION;
|
||||
static const char *CONFIG_NAME_KEY;
|
||||
static const char *CONFIG_BINARY_TYPE_KEY;
|
||||
static const char *CONFIG_BINARY_KEY;
|
||||
|
||||
static const char *DEPENDENCIES_SECTION;
|
||||
static const char *DEPENDENCIES_LOCAL_KEY;
|
||||
static const char *DEPENDENCIES_REMOTE_KEY;
|
||||
static const char *DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY;
|
||||
|
||||
static const char *BINARY_TYPE_LOCAL;
|
||||
static const char *BINARY_TYPE_REMOTE;
|
||||
|
||||
static const char *PLUGIN_VALUE_SEPARATOR;
|
||||
|
||||
// Set to true when the config file is properly loaded.
|
||||
bool valid_config = false;
|
||||
// Unix timestamp of last change to this plugin.
|
||||
uint64_t last_updated = 0;
|
||||
|
||||
// Required config section
|
||||
String name;
|
||||
String binary_type;
|
||||
String binary;
|
||||
|
||||
// Optional dependencies section
|
||||
Vector<String> local_dependencies;
|
||||
Vector<String> remote_dependencies;
|
||||
Vector<String> custom_maven_repos;
|
||||
};
|
||||
#include "godot_plugin_config.h"
|
||||
|
||||
const char *PluginConfigAndroid::PLUGIN_CONFIG_EXT = ".gdap";
|
||||
|
||||
|
@ -116,7 +62,7 @@ const char *PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR = "|";
|
|||
// /*.custom_maven_repos =*/{}
|
||||
// };
|
||||
|
||||
static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
|
||||
String PluginConfigAndroid::resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
|
||||
String absolute_path;
|
||||
if (!dependency_path.empty()) {
|
||||
if (dependency_path.is_abs_path()) {
|
||||
|
@ -129,7 +75,7 @@ static inline String resolve_local_dependency_path(String plugin_config_dir, Str
|
|||
return absolute_path;
|
||||
}
|
||||
|
||||
static inline PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) {
|
||||
PluginConfigAndroid PluginConfigAndroid::resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) {
|
||||
PluginConfigAndroid resolved = prebuilt_plugin;
|
||||
resolved.binary = resolved.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.binary) : prebuilt_plugin.binary;
|
||||
if (!prebuilt_plugin.local_dependencies.empty()) {
|
||||
|
@ -141,13 +87,13 @@ static inline PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid pr
|
|||
return resolved;
|
||||
}
|
||||
|
||||
static inline Vector<PluginConfigAndroid> get_prebuilt_plugins(String plugins_base_dir) {
|
||||
Vector<PluginConfigAndroid> PluginConfigAndroid::get_prebuilt_plugins(String plugins_base_dir) {
|
||||
Vector<PluginConfigAndroid> prebuilt_plugins;
|
||||
// prebuilt_plugins.push_back(resolve_prebuilt_plugin(MY_PREBUILT_PLUGIN, plugins_base_dir));
|
||||
return prebuilt_plugins;
|
||||
}
|
||||
|
||||
static inline bool is_plugin_config_valid(PluginConfigAndroid plugin_config) {
|
||||
bool PluginConfigAndroid::is_plugin_config_valid(PluginConfigAndroid plugin_config) {
|
||||
bool valid_name = !plugin_config.name.empty();
|
||||
bool valid_binary_type = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ||
|
||||
plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE;
|
||||
|
@ -171,19 +117,19 @@ static inline bool is_plugin_config_valid(PluginConfigAndroid plugin_config) {
|
|||
return valid_name && valid_binary && valid_binary_type && valid_local_dependencies;
|
||||
}
|
||||
|
||||
static inline uint64_t get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) {
|
||||
uint64_t last_updated = FileAccess::get_modified_time(config_path);
|
||||
last_updated = MAX(last_updated, FileAccess::get_modified_time(plugin_config.binary));
|
||||
uint64_t PluginConfigAndroid::get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) {
|
||||
uint64_t last_modified = FileAccess::get_modified_time(config_path);
|
||||
last_modified = MAX(last_modified, FileAccess::get_modified_time(plugin_config.binary));
|
||||
|
||||
for (int i = 0; i < plugin_config.local_dependencies.size(); i++) {
|
||||
String binary = plugin_config.local_dependencies.get(i);
|
||||
last_updated = MAX(last_updated, FileAccess::get_modified_time(binary));
|
||||
String local_dependency = plugin_config.local_dependencies.get(i);
|
||||
last_modified = MAX(last_modified, FileAccess::get_modified_time(local_dependency));
|
||||
}
|
||||
|
||||
return last_updated;
|
||||
return last_modified;
|
||||
}
|
||||
|
||||
static inline PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
|
||||
PluginConfigAndroid PluginConfigAndroid::load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
|
||||
PluginConfigAndroid plugin_config = {};
|
||||
|
||||
if (config_file.is_valid()) {
|
||||
|
@ -217,7 +163,7 @@ static inline PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file
|
|||
return plugin_config;
|
||||
}
|
||||
|
||||
static inline String get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String PluginConfigAndroid::get_plugins_binaries(String type, Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String plugins_binaries;
|
||||
if (!plugins_configs.empty()) {
|
||||
Vector<String> binaries;
|
||||
|
@ -227,15 +173,15 @@ static inline String get_plugins_binaries(String binary_type, Vector<PluginConfi
|
|||
continue;
|
||||
}
|
||||
|
||||
if (config.binary_type == binary_type) {
|
||||
if (config.binary_type == type) {
|
||||
binaries.push_back(config.binary);
|
||||
}
|
||||
|
||||
if (binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL) {
|
||||
if (type == PluginConfigAndroid::BINARY_TYPE_LOCAL) {
|
||||
binaries.append_array(config.local_dependencies);
|
||||
}
|
||||
|
||||
if (binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE) {
|
||||
if (type == PluginConfigAndroid::BINARY_TYPE_REMOTE) {
|
||||
binaries.append_array(config.remote_dependencies);
|
||||
}
|
||||
}
|
||||
|
@ -246,8 +192,8 @@ static inline String get_plugins_binaries(String binary_type, Vector<PluginConfi
|
|||
return plugins_binaries;
|
||||
}
|
||||
|
||||
static inline String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String custom_maven_repos;
|
||||
String PluginConfigAndroid::get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String maven_repos;
|
||||
if (!plugins_configs.empty()) {
|
||||
Vector<String> repos_urls;
|
||||
for (int i = 0; i < plugins_configs.size(); i++) {
|
||||
|
@ -259,12 +205,12 @@ static inline String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid>
|
|||
repos_urls.append_array(config.custom_maven_repos);
|
||||
}
|
||||
|
||||
custom_maven_repos = String(PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR).join(repos_urls);
|
||||
maven_repos = String(PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR).join(repos_urls);
|
||||
}
|
||||
return custom_maven_repos;
|
||||
return maven_repos;
|
||||
}
|
||||
|
||||
static inline String get_plugins_names(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String PluginConfigAndroid::get_plugins_names(Vector<PluginConfigAndroid> plugins_configs) {
|
||||
String plugins_names;
|
||||
if (!plugins_configs.empty()) {
|
||||
Vector<String> names;
|
||||
|
@ -281,5 +227,3 @@ static inline String get_plugins_names(Vector<PluginConfigAndroid> plugins_confi
|
|||
|
||||
return plugins_names;
|
||||
}
|
||||
|
||||
#endif // GODOT_PLUGIN_CONFIG_H
|
106
platform/android/export/godot_plugin_config.h
Normal file
106
platform/android/export/godot_plugin_config.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*************************************************************************/
|
||||
/* godot_plugin_config.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef ANDROID_GODOT_PLUGIN_CONFIG_H
|
||||
#define ANDROID_GODOT_PLUGIN_CONFIG_H
|
||||
|
||||
#include "core/error_list.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
/*
|
||||
The `config` section and fields are required and defined as follow:
|
||||
- **name**: name of the plugin.
|
||||
- **binary_type**: can be either `local` or `remote`. The type affects the **binary** field.
|
||||
- **binary**:
|
||||
- if **binary_type** is `local`, then this should be the filename of the plugin `aar` file in the `res://android/plugins` directory (e.g: `MyPlugin.aar`).
|
||||
- if **binary_type** is `remote`, then this should be a declaration for a remote gradle binary (e.g: "org.godot.example:my-plugin:0.0.0").
|
||||
|
||||
The `dependencies` section and fields are optional and defined as follow:
|
||||
- **local**: contains a list of local `.aar` binary files the plugin depends on. The local binary dependencies must also be located in the `res://android/plugins` directory.
|
||||
- **remote**: contains a list of remote binary gradle dependencies for the plugin.
|
||||
- **custom_maven_repos**: contains a list of urls specifying custom maven repos required for the plugin's dependencies.
|
||||
|
||||
See https://github.com/godotengine/godot/issues/38157#issuecomment-618773871
|
||||
*/
|
||||
struct PluginConfigAndroid {
|
||||
static const char *PLUGIN_CONFIG_EXT;
|
||||
|
||||
static const char *CONFIG_SECTION;
|
||||
static const char *CONFIG_NAME_KEY;
|
||||
static const char *CONFIG_BINARY_TYPE_KEY;
|
||||
static const char *CONFIG_BINARY_KEY;
|
||||
|
||||
static const char *DEPENDENCIES_SECTION;
|
||||
static const char *DEPENDENCIES_LOCAL_KEY;
|
||||
static const char *DEPENDENCIES_REMOTE_KEY;
|
||||
static const char *DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY;
|
||||
|
||||
static const char *BINARY_TYPE_LOCAL;
|
||||
static const char *BINARY_TYPE_REMOTE;
|
||||
|
||||
static const char *PLUGIN_VALUE_SEPARATOR;
|
||||
|
||||
// Set to true when the config file is properly loaded.
|
||||
bool valid_config = false;
|
||||
// Unix timestamp of last change to this plugin.
|
||||
uint64_t last_updated = 0;
|
||||
|
||||
// Required config section
|
||||
String name;
|
||||
String binary_type;
|
||||
String binary;
|
||||
|
||||
// Optional dependencies section
|
||||
Vector<String> local_dependencies;
|
||||
Vector<String> remote_dependencies;
|
||||
Vector<String> custom_maven_repos;
|
||||
|
||||
static String resolve_local_dependency_path(String plugin_config_dir, String dependency_path);
|
||||
|
||||
static PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir);
|
||||
|
||||
static Vector<PluginConfigAndroid> get_prebuilt_plugins(String plugins_base_dir);
|
||||
|
||||
static bool is_plugin_config_valid(PluginConfigAndroid plugin_config);
|
||||
|
||||
static uint64_t get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path);
|
||||
|
||||
static PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file, const String &path);
|
||||
|
||||
static String get_plugins_binaries(String type, Vector<PluginConfigAndroid> plugins_configs);
|
||||
|
||||
static String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs);
|
||||
|
||||
static String get_plugins_names(Vector<PluginConfigAndroid> plugins_configs);
|
||||
};
|
||||
|
||||
#endif // ANDROID_GODOT_PLUGIN_CONFIG_H
|
266
platform/android/export/gradle_export_util.cpp
Normal file
266
platform/android/export/gradle_export_util.cpp
Normal file
|
@ -0,0 +1,266 @@
|
|||
/*************************************************************************/
|
||||
/* gradle_export_util.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "gradle_export_util.h"
|
||||
|
||||
int _get_android_orientation_value(OS::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case OS::SCREEN_PORTRAIT:
|
||||
return 1;
|
||||
case OS::SCREEN_REVERSE_LANDSCAPE:
|
||||
return 8;
|
||||
case OS::SCREEN_REVERSE_PORTRAIT:
|
||||
return 9;
|
||||
case OS::SCREEN_SENSOR_LANDSCAPE:
|
||||
return 11;
|
||||
case OS::SCREEN_SENSOR_PORTRAIT:
|
||||
return 12;
|
||||
case OS::SCREEN_SENSOR:
|
||||
return 13;
|
||||
case OS::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String _get_android_orientation_label(OS::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case OS::SCREEN_PORTRAIT:
|
||||
return "portrait";
|
||||
case OS::SCREEN_REVERSE_LANDSCAPE:
|
||||
return "reverseLandscape";
|
||||
case OS::SCREEN_REVERSE_PORTRAIT:
|
||||
return "reversePortrait";
|
||||
case OS::SCREEN_SENSOR_LANDSCAPE:
|
||||
return "userLandscape";
|
||||
case OS::SCREEN_SENSOR_PORTRAIT:
|
||||
return "userPortrait";
|
||||
case OS::SCREEN_SENSOR:
|
||||
return "fullUser";
|
||||
case OS::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return "landscape";
|
||||
}
|
||||
}
|
||||
|
||||
// Utility method used to create a directory.
|
||||
Error create_directory(const String &p_dir) {
|
||||
if (!DirAccess::exists(p_dir)) {
|
||||
DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
Error err = filesystem_da->make_dir_recursive(p_dir);
|
||||
ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
memdelete(filesystem_da);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Writes p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_buffer(p_data.ptr(), p_data.size());
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Writes string p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_string_at_path(const String &p_path, const String &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to write data into " + p_path);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_string(p_data);
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Implementation of EditorExportSaveFunction.
|
||||
// This method will only be called as an input to export_project_files.
|
||||
// It is used by the export_project_files method to save all the asset files into the gradle project.
|
||||
// It's functionality mirrors that of the method save_apk_file.
|
||||
// This method will be called ONLY when custom build is enabled.
|
||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
|
||||
String dst_path = p_path.replace_first("res://", "res://android/build/assets/");
|
||||
print_verbose("Saving project files from " + p_path + " into " + dst_path);
|
||||
Error err = store_file_at_path(dst_path, p_data);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Creates strings.xml files inside the gradle project for different locales.
|
||||
Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset, const String &project_name) {
|
||||
print_verbose("Creating strings resources for supported locales for project " + project_name);
|
||||
// Stores the string into the default values directory.
|
||||
String processed_default_xml_string = vformat(godot_project_name_xml_string, project_name.xml_escape(true));
|
||||
store_string_at_path("res://android/build/res/values/godot_project_name_string.xml", processed_default_xml_string);
|
||||
|
||||
// Searches the Gradle project res/ directory to find all supported locales
|
||||
DirAccessRef da = DirAccess::open("res://android/build/res");
|
||||
if (!da) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to open Android resources directory.");
|
||||
}
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
if (file == "") {
|
||||
break;
|
||||
}
|
||||
if (!file.begins_with("values-")) {
|
||||
// NOTE: This assumes all directories that start with "values-" are for localization.
|
||||
continue;
|
||||
}
|
||||
String locale = file.replace("values-", "").replace("-r", "_");
|
||||
String property_name = "application/config/name_" + locale;
|
||||
String locale_directory = "res://android/build/res/" + file + "/godot_project_name_string.xml";
|
||||
if (ProjectSettings::get_singleton()->has_setting(property_name)) {
|
||||
String locale_project_name = ProjectSettings::get_singleton()->get(property_name);
|
||||
String processed_xml_string = vformat(godot_project_name_xml_string, locale_project_name.xml_escape(true));
|
||||
print_verbose("Storing project name for locale " + locale + " under " + locale_directory);
|
||||
store_string_at_path(locale_directory, processed_xml_string);
|
||||
} else {
|
||||
// TODO: Once the legacy build system is deprecated we don't need to have xml files for this else branch
|
||||
store_string_at_path(locale_directory, processed_default_xml_string);
|
||||
}
|
||||
}
|
||||
da->list_dir_end();
|
||||
return OK;
|
||||
}
|
||||
|
||||
String bool_to_string(bool v) {
|
||||
return v ? "true" : "false";
|
||||
}
|
||||
|
||||
String _get_gles_tag() {
|
||||
bool min_gles3 = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name") == "GLES3" &&
|
||||
!ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2");
|
||||
return min_gles3 ? " <uses-feature android:glEsVersion=\"0x00030000\" android:required=\"true\" />\n" : "";
|
||||
}
|
||||
|
||||
String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_screen_sizes = " <supports-screens \n tools:node=\"replace\"";
|
||||
String sizes[] = { "small", "normal", "large", "xlarge" };
|
||||
size_t num_sizes = sizeof(sizes) / sizeof(sizes[0]);
|
||||
for (size_t i = 0; i < num_sizes; i++) {
|
||||
String feature_name = vformat("screen/support_%s", sizes[i]);
|
||||
String feature_support = bool_to_string(p_preset->get(feature_name));
|
||||
String xml_entry = vformat("\n android:%sScreens=\"%s\"", sizes[i], feature_support);
|
||||
manifest_screen_sizes += xml_entry;
|
||||
}
|
||||
manifest_screen_sizes += " />\n";
|
||||
return manifest_screen_sizes;
|
||||
}
|
||||
|
||||
String _get_xr_features_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_xr_features;
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
if (uses_xr) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"android.hardware.vr.headtracking\" android:required=\"true\" android:version=\"1\" />\n";
|
||||
|
||||
int hand_tracking_index = p_preset->get("xr_features/hand_tracking"); // 0: none, 1: optional, 2: required
|
||||
if (hand_tracking_index == 1) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"false\" />\n";
|
||||
} else if (hand_tracking_index == 2) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"true\" />\n";
|
||||
}
|
||||
}
|
||||
return manifest_xr_features;
|
||||
}
|
||||
|
||||
String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String package_name = p_preset->get("package/unique_name");
|
||||
String manifest_instrumentation_text = vformat(
|
||||
" <instrumentation\n"
|
||||
" tools:node=\"replace\"\n"
|
||||
" android:name=\".GodotInstrumentation\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:targetPackage=\"%s\" />\n",
|
||||
package_name);
|
||||
return manifest_instrumentation_text;
|
||||
}
|
||||
|
||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
String orientation = _get_android_orientation_label(
|
||||
OS::get_singleton()->get_screen_orientation_from_string(GLOBAL_GET("display/window/handheld/orientation")));
|
||||
String manifest_activity_text = vformat(
|
||||
" <activity android:name=\"com.godot.game.GodotApp\" "
|
||||
"tools:replace=\"android:screenOrientation\" "
|
||||
"android:screenOrientation=\"%s\">\n",
|
||||
orientation);
|
||||
if (uses_xr) {
|
||||
manifest_activity_text += " <meta-data tools:node=\"replace\" android:name=\"com.oculus.vr.focusaware\" android:value=\"true\" />\n";
|
||||
} else {
|
||||
manifest_activity_text += " <meta-data tools:node=\"remove\" android:name=\"com.oculus.vr.focusaware\" />\n";
|
||||
}
|
||||
manifest_activity_text += " </activity>\n";
|
||||
return manifest_activity_text;
|
||||
}
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset, bool p_has_storage_permission) {
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
String manifest_application_text = vformat(
|
||||
" <application android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:allowBackup=\"%s\"\n"
|
||||
" android:isGame=\"%s\"\n"
|
||||
" android:hasFragileUserData=\"%s\"\n"
|
||||
" android:requestLegacyExternalStorage=\"%s\"\n"
|
||||
" tools:replace=\"android:allowBackup,android:isGame,android:hasFragileUserData,android:requestLegacyExternalStorage\"\n"
|
||||
" tools:ignore=\"GoogleAppIndexingWarning\"\n"
|
||||
" android:icon=\"@mipmap/icon\" >\n\n"
|
||||
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n",
|
||||
bool_to_string(p_preset->get("user_data_backup/allow")),
|
||||
bool_to_string(p_preset->get("package/classify_as_game")),
|
||||
bool_to_string(p_preset->get("package/retain_data_on_uninstall")),
|
||||
bool_to_string(p_has_storage_permission));
|
||||
|
||||
if (uses_xr) {
|
||||
manifest_application_text += " <meta-data tools:node=\"replace\" android:name=\"com.samsung.android.vr.application.mode\" android:value=\"vr_only\" />\n";
|
||||
}
|
||||
manifest_application_text += _get_activity_tag(p_preset);
|
||||
manifest_application_text += " </application>\n";
|
||||
return manifest_application_text;
|
||||
}
|
|
@ -44,239 +44,43 @@ const String godot_project_name_xml_string = R"(<?xml version="1.0" encoding="ut
|
|||
</resources>
|
||||
)";
|
||||
|
||||
int _get_android_orientation_value(OS::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case OS::SCREEN_PORTRAIT:
|
||||
return 1;
|
||||
case OS::SCREEN_REVERSE_LANDSCAPE:
|
||||
return 8;
|
||||
case OS::SCREEN_REVERSE_PORTRAIT:
|
||||
return 9;
|
||||
case OS::SCREEN_SENSOR_LANDSCAPE:
|
||||
return 11;
|
||||
case OS::SCREEN_SENSOR_PORTRAIT:
|
||||
return 12;
|
||||
case OS::SCREEN_SENSOR:
|
||||
return 13;
|
||||
case OS::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int _get_android_orientation_value(OS::ScreenOrientation screen_orientation);
|
||||
|
||||
String _get_android_orientation_label(OS::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
case OS::SCREEN_PORTRAIT:
|
||||
return "portrait";
|
||||
case OS::SCREEN_REVERSE_LANDSCAPE:
|
||||
return "reverseLandscape";
|
||||
case OS::SCREEN_REVERSE_PORTRAIT:
|
||||
return "reversePortrait";
|
||||
case OS::SCREEN_SENSOR_LANDSCAPE:
|
||||
return "userLandscape";
|
||||
case OS::SCREEN_SENSOR_PORTRAIT:
|
||||
return "userPortrait";
|
||||
case OS::SCREEN_SENSOR:
|
||||
return "fullUser";
|
||||
case OS::SCREEN_LANDSCAPE:
|
||||
default:
|
||||
return "landscape";
|
||||
}
|
||||
}
|
||||
String _get_android_orientation_label(OS::ScreenOrientation screen_orientation);
|
||||
|
||||
// Utility method used to create a directory.
|
||||
Error create_directory(const String &p_dir) {
|
||||
if (!DirAccess::exists(p_dir)) {
|
||||
DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
ERR_FAIL_COND_V_MSG(!filesystem_da, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
Error err = filesystem_da->make_dir_recursive(p_dir);
|
||||
ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "Cannot create directory '" + p_dir + "'.");
|
||||
memdelete(filesystem_da);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
Error create_directory(const String &p_dir);
|
||||
|
||||
// Writes p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_buffer(p_data.ptr(), p_data.size());
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data);
|
||||
|
||||
// Writes string p_data into a file at p_path, creating directories if necessary.
|
||||
// Note: this will overwrite the file at p_path if it already exists.
|
||||
Error store_string_at_path(const String &p_path, const String &p_data) {
|
||||
String dir = p_path.get_base_dir();
|
||||
Error err = create_directory(dir);
|
||||
if (err != OK) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to write data into " + p_path);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
|
||||
fa->store_string(p_data);
|
||||
memdelete(fa);
|
||||
return OK;
|
||||
}
|
||||
Error store_string_at_path(const String &p_path, const String &p_data);
|
||||
|
||||
// Implementation of EditorExportSaveFunction.
|
||||
// This method will only be called as an input to export_project_files.
|
||||
// It is used by the export_project_files method to save all the asset files into the gradle project.
|
||||
// It's functionality mirrors that of the method save_apk_file.
|
||||
// This method will be called ONLY when custom build is enabled.
|
||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
|
||||
String dst_path = p_path.replace_first("res://", "res://android/build/assets/");
|
||||
print_verbose("Saving project files from " + p_path + " into " + dst_path);
|
||||
Error err = store_file_at_path(dst_path, p_data);
|
||||
return err;
|
||||
}
|
||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
|
||||
|
||||
// Creates strings.xml files inside the gradle project for different locales.
|
||||
Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset, const String &project_name) {
|
||||
print_verbose("Creating strings resources for supported locales for project " + project_name);
|
||||
// Stores the string into the default values directory.
|
||||
String processed_default_xml_string = vformat(godot_project_name_xml_string, project_name.xml_escape(true));
|
||||
store_string_at_path("res://android/build/res/values/godot_project_name_string.xml", processed_default_xml_string);
|
||||
Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset, const String &project_name);
|
||||
|
||||
// Searches the Gradle project res/ directory to find all supported locales
|
||||
DirAccessRef da = DirAccess::open("res://android/build/res");
|
||||
if (!da) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("Unable to open Android resources directory.");
|
||||
}
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
if (file == "") {
|
||||
break;
|
||||
}
|
||||
if (!file.begins_with("values-")) {
|
||||
// NOTE: This assumes all directories that start with "values-" are for localization.
|
||||
continue;
|
||||
}
|
||||
String locale = file.replace("values-", "").replace("-r", "_");
|
||||
String property_name = "application/config/name_" + locale;
|
||||
String locale_directory = "res://android/build/res/" + file + "/godot_project_name_string.xml";
|
||||
if (ProjectSettings::get_singleton()->has_setting(property_name)) {
|
||||
String locale_project_name = ProjectSettings::get_singleton()->get(property_name);
|
||||
String processed_xml_string = vformat(godot_project_name_xml_string, locale_project_name.xml_escape(true));
|
||||
print_verbose("Storing project name for locale " + locale + " under " + locale_directory);
|
||||
store_string_at_path(locale_directory, processed_xml_string);
|
||||
} else {
|
||||
// TODO: Once the legacy build system is deprecated we don't need to have xml files for this else branch
|
||||
store_string_at_path(locale_directory, processed_default_xml_string);
|
||||
}
|
||||
}
|
||||
da->list_dir_end();
|
||||
return OK;
|
||||
}
|
||||
String bool_to_string(bool v);
|
||||
|
||||
String bool_to_string(bool v) {
|
||||
return v ? "true" : "false";
|
||||
}
|
||||
String _get_gles_tag();
|
||||
|
||||
String _get_gles_tag() {
|
||||
bool min_gles3 = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name") == "GLES3" &&
|
||||
!ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2");
|
||||
return min_gles3 ? " <uses-feature android:glEsVersion=\"0x00030000\" android:required=\"true\" />\n" : "";
|
||||
}
|
||||
String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_screen_sizes = " <supports-screens \n tools:node=\"replace\"";
|
||||
String sizes[] = { "small", "normal", "large", "xlarge" };
|
||||
size_t num_sizes = sizeof(sizes) / sizeof(sizes[0]);
|
||||
for (size_t i = 0; i < num_sizes; i++) {
|
||||
String feature_name = vformat("screen/support_%s", sizes[i]);
|
||||
String feature_support = bool_to_string(p_preset->get(feature_name));
|
||||
String xml_entry = vformat("\n android:%sScreens=\"%s\"", sizes[i], feature_support);
|
||||
manifest_screen_sizes += xml_entry;
|
||||
}
|
||||
manifest_screen_sizes += " />\n";
|
||||
return manifest_screen_sizes;
|
||||
}
|
||||
String _get_xr_features_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_xr_features_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String manifest_xr_features;
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
if (uses_xr) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"android.hardware.vr.headtracking\" android:required=\"true\" android:version=\"1\" />\n";
|
||||
String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
int hand_tracking_index = p_preset->get("xr_features/hand_tracking"); // 0: none, 1: optional, 2: required
|
||||
if (hand_tracking_index == 1) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"false\" />\n";
|
||||
} else if (hand_tracking_index == 2) {
|
||||
manifest_xr_features += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"true\" />\n";
|
||||
}
|
||||
}
|
||||
return manifest_xr_features;
|
||||
}
|
||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
String package_name = p_preset->get("package/unique_name");
|
||||
String manifest_instrumentation_text = vformat(
|
||||
" <instrumentation\n"
|
||||
" tools:node=\"replace\"\n"
|
||||
" android:name=\".GodotInstrumentation\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:targetPackage=\"%s\" />\n",
|
||||
package_name);
|
||||
return manifest_instrumentation_text;
|
||||
}
|
||||
|
||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
String orientation = _get_android_orientation_label(
|
||||
OS::get_singleton()->get_screen_orientation_from_string(GLOBAL_GET("display/window/handheld/orientation")));
|
||||
String manifest_activity_text = vformat(
|
||||
" <activity android:name=\"com.godot.game.GodotApp\" "
|
||||
"tools:replace=\"android:screenOrientation\" "
|
||||
"android:screenOrientation=\"%s\">\n",
|
||||
orientation);
|
||||
if (uses_xr) {
|
||||
manifest_activity_text += " <meta-data tools:node=\"replace\" android:name=\"com.oculus.vr.focusaware\" android:value=\"true\" />\n";
|
||||
} else {
|
||||
manifest_activity_text += " <meta-data tools:node=\"remove\" android:name=\"com.oculus.vr.focusaware\" />\n";
|
||||
}
|
||||
manifest_activity_text += " </activity>\n";
|
||||
return manifest_activity_text;
|
||||
}
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset, bool p_has_storage_permission) {
|
||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||
String manifest_application_text = vformat(
|
||||
" <application android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:allowBackup=\"%s\"\n"
|
||||
" android:isGame=\"%s\"\n"
|
||||
" android:hasFragileUserData=\"%s\"\n"
|
||||
" android:requestLegacyExternalStorage=\"%s\"\n"
|
||||
" tools:replace=\"android:allowBackup,android:isGame,android:hasFragileUserData,android:requestLegacyExternalStorage\"\n"
|
||||
" tools:ignore=\"GoogleAppIndexingWarning\"\n"
|
||||
" android:icon=\"@mipmap/icon\" >\n\n"
|
||||
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n",
|
||||
bool_to_string(p_preset->get("user_data_backup/allow")),
|
||||
bool_to_string(p_preset->get("package/classify_as_game")),
|
||||
bool_to_string(p_preset->get("package/retain_data_on_uninstall")),
|
||||
bool_to_string(p_has_storage_permission));
|
||||
|
||||
if (uses_xr) {
|
||||
manifest_application_text += " <meta-data tools:node=\"replace\" android:name=\"com.samsung.android.vr.application.mode\" android:value=\"vr_only\" />\n";
|
||||
}
|
||||
manifest_application_text += _get_activity_tag(p_preset);
|
||||
manifest_application_text += " </application>\n";
|
||||
return manifest_application_text;
|
||||
}
|
||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset, bool p_has_storage_permission);
|
||||
|
||||
#endif //GODOT_GRADLE_EXPORT_UTIL_H
|
||||
|
|
Loading…
Reference in a new issue