diff options
Diffstat (limited to 'platform/android/export/export_plugin.cpp')
-rw-r--r-- | platform/android/export/export_plugin.cpp | 118 |
1 files changed, 89 insertions, 29 deletions
diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index f8ac591a78..e20de99c2d 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -68,6 +68,7 @@ static const char *android_perms[] = { "ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION", "ACCESS_LOCATION_EXTRA_COMMANDS", + "ACCESS_MEDIA_LOCATION", "ACCESS_MOCK_LOCATION", "ACCESS_NETWORK_STATE", "ACCESS_SURFACE_FLINGER", @@ -155,6 +156,10 @@ static const char *android_perms[] = { "READ_HISTORY_BOOKMARKS", "READ_INPUT_STATE", "READ_LOGS", + "READ_MEDIA_AUDIO", + "READ_MEDIA_IMAGES", + "READ_MEDIA_VIDEO", + "READ_MEDIA_VISUAL_USER_SELECTED", "READ_PHONE_STATE", "READ_PROFILE", "READ_SMS", @@ -222,6 +227,7 @@ static const int icon_densities_count = 6; static const char *launcher_icon_option = PNAME("launcher_icons/main_192x192"); static const char *launcher_adaptive_icon_foreground_option = PNAME("launcher_icons/adaptive_foreground_432x432"); static const char *launcher_adaptive_icon_background_option = PNAME("launcher_icons/adaptive_background_432x432"); +static const char *launcher_adaptive_icon_monochrome_option = PNAME("launcher_icons/adaptive_monochrome_432x432"); static const LauncherIcon launcher_icons[icon_densities_count] = { { "res/mipmap-xxxhdpi-v4/icon.png", 192 }, @@ -250,6 +256,15 @@ static const LauncherIcon launcher_adaptive_icon_backgrounds[icon_densities_coun { "res/mipmap/icon_background.png", 432 } }; +static const LauncherIcon launcher_adaptive_icon_monochromes[icon_densities_count] = { + { "res/mipmap-xxxhdpi-v4/icon_monochrome.png", 432 }, + { "res/mipmap-xxhdpi-v4/icon_monochrome.png", 324 }, + { "res/mipmap-xhdpi-v4/icon_monochrome.png", 216 }, + { "res/mipmap-hdpi-v4/icon_monochrome.png", 162 }, + { "res/mipmap-mdpi-v4/icon_monochrome.png", 108 }, + { "res/mipmap/icon_monochrome.png", 432 } +}; + static const int EXPORT_FORMAT_APK = 0; static const int EXPORT_FORMAT_AAB = 1; @@ -294,7 +309,9 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { // Check for devices updates String adb = get_adb_path(); - if (ea->has_runnable_preset.is_set() && FileAccess::exists(adb)) { + // adb.exe was locking the editor_doc_cache file on startup. Adding a check for is_editor_ready provides just enough time + // to regenerate the doc cache. + if (ea->has_runnable_preset.is_set() && FileAccess::exists(adb) && EditorNode::get_singleton()->is_editor_ready()) { String devices; List<String> args; args.push_back("devices"); @@ -771,15 +788,16 @@ Error EditorExportPlatformAndroid::save_apk_so(void *p_userdata, const SharedObj return OK; } -Error EditorExportPlatformAndroid::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) { +Error EditorExportPlatformAndroid::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, uint64_t p_seed) { APKExportData *ed = static_cast<APKExportData *>(p_userdata); - String dst_path = p_path.replace_first("res://", "assets/"); + const String path = ResourceUID::ensure_path(p_path); + const String dst_path = path.replace_first("res://", "assets/"); - store_in_apk(ed, dst_path, p_data, _should_compress_asset(p_path, p_data) ? Z_DEFLATED : 0); + store_in_apk(ed, dst_path, p_data, _should_compress_asset(path, p_data) ? Z_DEFLATED : 0); return OK; } -Error EditorExportPlatformAndroid::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) { +Error EditorExportPlatformAndroid::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, uint64_t p_seed) { return OK; } @@ -1547,7 +1565,7 @@ void EditorExportPlatformAndroid::_fix_resources(const Ref<EditorExportPreset> & str = get_project_name(package_name); } else { - String lang = str.substr(str.rfind("-") + 1, str.length()).replace("-", "_"); + String lang = str.substr(str.rfind_char('-') + 1, str.length()).replace("-", "_"); if (appnames.has(lang)) { str = appnames[lang]; } else { @@ -1642,12 +1660,13 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n } } -void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background) { +void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background, Ref<Image> &monochrome) { String project_icon_path = GLOBAL_GET("application/config/icon"); icon.instantiate(); foreground.instantiate(); background.instantiate(); + monochrome.instantiate(); // Regular icon: user selection -> project icon -> default. String path = static_cast<String>(p_preset->get(launcher_icon_option)).strip_edges(); @@ -1675,12 +1694,20 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> & print_verbose("Loading adaptive background icon from " + path); ImageLoader::load_image(path, background); } + + // Adaptive monochrome: user selection -> default. + path = static_cast<String>(p_preset->get(launcher_adaptive_icon_monochrome_option)).strip_edges(); + if (!path.is_empty()) { + print_verbose("Loading adaptive monochrome icon from " + path); + ImageLoader::load_image(path, monochrome); + } } void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_main_image, const Ref<Image> &p_foreground, - const Ref<Image> &p_background) { + const Ref<Image> &p_background, + const Ref<Image> &p_monochrome) { String gradle_build_dir = ExportTemplateManager::get_android_build_directory(p_preset); // Prepare images to be resized for the icons. If some image ends up being uninitialized, @@ -1709,6 +1736,14 @@ void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref<Editor launcher_adaptive_icon_backgrounds[i].dimensions, data); store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_backgrounds[i].export_path), data); } + + if (p_monochrome.is_valid() && !p_monochrome->is_empty()) { + print_verbose("Processing launcher adaptive icon p_monochrome for dimension " + itos(launcher_adaptive_icon_monochromes[i].dimensions) + " into " + launcher_adaptive_icon_monochromes[i].export_path); + Vector<uint8_t> data; + _process_launcher_icons(launcher_adaptive_icon_monochromes[i].export_path, p_monochrome, + launcher_adaptive_icon_monochromes[i].dimensions, data); + store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_monochromes[i].export_path), data); + } } } @@ -1749,6 +1784,12 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport if (!is_package_name_valid(pn, &pn_err)) { return TTR("Invalid package name:") + " " + pn_err; } + } else if (p_name == launcher_adaptive_icon_monochrome_option) { + String monochrome_icon_path = p_preset->get(launcher_adaptive_icon_monochrome_option); + + if (monochrome_icon_path.is_empty()) { + return TTR("No adaptive monochrome icon specified; default Godot monochrome icon will be used."); + } } else if (p_name == "gradle_build/use_gradle_build") { bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build"); String enabled_plugins_names = _get_plugins_names(Ref<EditorExportPreset>(p_preset)); @@ -1863,7 +1904,7 @@ void EditorExportPlatformAndroid::get_export_options(List<ExportOption> *r_optio r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "ext.domain.name"), "com.example.$genname", false, true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name [default if blank]"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/signed"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "package/app_category", PROPERTY_HINT_ENUM, "Accessibility,Audio,Game,Image,Maps,News,Productivity,Social,Video"), APP_CATEGORY_GAME)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "package/app_category", PROPERTY_HINT_ENUM, "Accessibility,Audio,Game,Image,Maps,News,Productivity,Social,Video,Undefined"), APP_CATEGORY_GAME)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/retain_data_on_uninstall"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/exclude_from_recents"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/show_in_android_tv"), false)); @@ -1873,6 +1914,7 @@ void EditorExportPlatformAndroid::get_export_options(List<ExportOption> *r_optio r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_icon_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_foreground_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_background_option, PROPERTY_HINT_FILE, "*.png"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_monochrome_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "graphics/opengl_debug"), false)); @@ -2276,6 +2318,11 @@ String EditorExportPlatformAndroid::get_apksigner_path(int p_target_sdk, bool p_ bool failed = false; String version_to_use; + String java_sdk_path = EDITOR_GET("export/android/java_sdk_path"); + if (!java_sdk_path.is_empty()) { + OS::get_singleton()->set_environment("JAVA_HOME", java_sdk_path); + } + List<String> args; args.push_back("--version"); String output; @@ -2374,19 +2421,6 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Edito #ifdef MODULE_MONO_ENABLED // Android export is still a work in progress, keep a message as a warning. err += TTR("Exporting to Android when using C#/.NET is experimental.") + "\n"; - - bool unsupported_arch = false; - Vector<ABI> enabled_abis = get_enabled_abis(p_preset); - for (ABI abi : enabled_abis) { - if (abi.arch != "arm64" && abi.arch != "x86_64") { - err += vformat(TTR("Android architecture %s not supported in C# projects."), abi.arch) + "\n"; - unsupported_arch = true; - } - } - if (unsupported_arch) { - r_error = err; - return false; - } #endif // Look for export templates (first official, and if defined custom templates). @@ -2865,6 +2899,14 @@ Error EditorExportPlatformAndroid::sign_apk(const Ref<EditorExportPreset> &p_pre #endif print_verbose("Successfully completed signing build."); + +#ifdef ANDROID_ENABLED + bool prompt_apk_install = EDITOR_GET("export/android/install_exported_apk"); + if (prompt_apk_install) { + OS_Android::get_singleton()->shell_open(apk_path); + } +#endif + return OK; } @@ -3041,8 +3083,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP Ref<Image> main_image; Ref<Image> foreground; Ref<Image> background; + Ref<Image> monochrome; - load_icon_refs(p_preset, main_image, foreground, background); + load_icon_refs(p_preset, main_image, foreground, background, monochrome); Vector<uint8_t> command_line_flags; // Write command line flags into the command_line_flags variable. @@ -3113,7 +3156,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Unable to overwrite res/*.xml files with project name.")); } // Copies the project icon files into the appropriate Gradle project directory. - _copy_icons_to_gradle_project(p_preset, main_image, foreground, background); + _copy_icons_to_gradle_project(p_preset, main_image, foreground, background, monochrome); // Write an AndroidManifest.xml file into the Gradle project directory. _write_tmp_manifest(p_preset, p_give_internet, p_debug); @@ -3128,9 +3171,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP user_data.libs_directory = gradle_build_directory.path_join("libs"); user_data.debug = p_debug; if (p_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT)) { - err = export_project_files(p_preset, p_debug, ignore_apk_file, &user_data, copy_gradle_so); + err = export_project_files(p_preset, p_debug, ignore_apk_file, nullptr, &user_data, copy_gradle_so); } else { - err = export_project_files(p_preset, p_debug, rename_and_store_file_in_gradle_project, &user_data, copy_gradle_so); + err = export_project_files(p_preset, p_debug, rename_and_store_file_in_gradle_project, nullptr, &user_data, copy_gradle_so); } if (err != OK) { add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not export project files to gradle project.")); @@ -3194,6 +3237,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP PluginConfigAndroid::get_plugins_custom_maven_repos(enabled_plugins, android_dependencies_maven_repos); #endif // DISABLE_DEPRECATED + bool has_dotnet_project = false; Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); for (int i = 0; i < export_plugins.size(); i++) { if (export_plugins[i]->supports_platform(Ref<EditorExportPlatform>(this))) { @@ -3211,6 +3255,11 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP PackedStringArray export_plugin_android_dependencies_maven_repos = export_plugins[i]->get_android_dependencies_maven_repos(Ref<EditorExportPlatform>(this), p_debug); android_dependencies_maven_repos.append_array(export_plugin_android_dependencies_maven_repos); } + + PackedStringArray features = export_plugins[i]->get_export_features(Ref<EditorExportPlatform>(this), p_debug); + if (features.has("dotnet")) { + has_dotnet_project = true; + } } bool clean_build_required = _is_clean_build_required(p_preset); @@ -3224,17 +3273,21 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP cmdline.push_back("clean"); } + String edition = has_dotnet_project ? "Mono" : "Standard"; String build_type = p_debug ? "Debug" : "Release"; if (export_format == EXPORT_FORMAT_AAB) { String bundle_build_command = vformat("bundle%s", build_type); cmdline.push_back(bundle_build_command); } else if (export_format == EXPORT_FORMAT_APK) { - String apk_build_command = vformat("assemble%s", build_type); + String apk_build_command = vformat("assemble%s%s", edition, build_type); cmdline.push_back(apk_build_command); } + String addons_directory = ProjectSettings::get_singleton()->globalize_path("res://addons"); + cmdline.push_back("-p"); // argument to specify the start directory. cmdline.push_back(build_path); // start directory. + cmdline.push_back("-Paddons_directory=" + addons_directory); // path to the addon directory as it may contain jar or aar dependencies cmdline.push_back("-Pexport_package_name=" + package_name); // argument to specify the package name. cmdline.push_back("-Pexport_version_code=" + version_code); // argument to specify the version code. cmdline.push_back("-Pexport_version_name=" + version_name); // argument to specify the version name. @@ -3312,6 +3365,8 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP copy_args.push_back("-p"); // argument to specify the start directory. copy_args.push_back(build_path); // start directory. + copy_args.push_back("-Pexport_edition=" + edition.to_lower()); + copy_args.push_back("-Pexport_build_type=" + build_type.to_lower()); String export_format_arg = export_format == EXPORT_FORMAT_AAB ? "aab" : "apk"; @@ -3443,6 +3498,11 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP _process_launcher_icons(file, background, launcher_adaptive_icon_backgrounds[i].dimensions, data); } } + if (monochrome.is_valid() && !monochrome->is_empty()) { + if (file == launcher_adaptive_icon_monochromes[i].export_path) { + _process_launcher_icons(file, monochrome, launcher_adaptive_icon_monochromes[i].dimensions, data); + } + } } } @@ -3504,7 +3564,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP APKExportData ed; ed.ep = &ep; ed.apk = unaligned_apk; - err = export_project_files(p_preset, p_debug, ignore_apk_file, &ed, save_apk_so); + err = export_project_files(p_preset, p_debug, ignore_apk_file, nullptr, &ed, save_apk_so); } else { if (apk_expansion) { err = save_apk_expansion_file(p_preset, p_debug, p_path); @@ -3516,7 +3576,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP APKExportData ed; ed.ep = &ep; ed.apk = unaligned_apk; - err = export_project_files(p_preset, p_debug, save_apk_file, &ed, save_apk_so); + err = export_project_files(p_preset, p_debug, save_apk_file, nullptr, &ed, save_apk_so); } } |