1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-05 17:15:09 +00:00

Add support for exporting to Google Play Instant

This commit is contained in:
kojurohan42
2025-05-23 22:00:14 +05:45
parent 4a44078451
commit 12ad9ed4e0
5 changed files with 50 additions and 3 deletions

View File

@@ -280,6 +280,7 @@ static const int EXPORT_FORMAT_AAB = 1;
static const char *APK_ASSETS_DIRECTORY = "assets";
static const char *AAB_ASSETS_DIRECTORY = "assetPackInstallTime/src/main/assets";
static const char *INSTANT_APP_ASSETS_DIRECTORY = "assets"; // instant build doesn't support installTime assetspacks, so using the same directory as APK
static const int DEFAULT_MIN_SDK_VERSION = 24; // Should match the value in 'platform/android/java/app/config.gradle#minSdk'
static const int DEFAULT_TARGET_SDK_VERSION = 35; // Should match the value in 'platform/android/java/app/config.gradle#targetSdk'
@@ -524,6 +525,12 @@ String EditorExportPlatformAndroid::get_valid_basename(const Ref<EditorExportPre
String EditorExportPlatformAndroid::get_assets_directory(const Ref<EditorExportPreset> &p_preset, int p_export_format) const {
String gradle_build_directory = ExportTemplateManager::get_android_build_directory(p_preset);
bool google_play_instant_build = p_preset->get("gradle_build/google_play_instant");
if (google_play_instant_build) {
return gradle_build_directory.path_join(INSTANT_APP_ASSETS_DIRECTORY); // Always use base APK asset format
}
return gradle_build_directory.path_join(p_export_format == EXPORT_FORMAT_AAB ? AAB_ASSETS_DIRECTORY : APK_ASSETS_DIRECTORY);
}
@@ -993,10 +1000,19 @@ void EditorExportPlatformAndroid::_get_manifest_info(const Ref<EditorExportPrese
void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug) {
print_verbose("Building temporary manifest...");
bool google_play_instant_build = (bool)p_preset->get("gradle_build/google_play_instant");
String manifest_text =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n"
" xmlns:tools=\"http://schemas.android.com/tools\">\n";
" xmlns:tools=\"http://schemas.android.com/tools\"";
if (google_play_instant_build) {
manifest_text += " android:targetSandboxVersion=\"2\" \n xmlns:dist=\"http://schemas.android.com/apk/distribution\"";
}
manifest_text += ">\n";
manifest_text += _get_screen_sizes_tag(p_preset);
manifest_text += _get_gles_tag();
@@ -1030,6 +1046,7 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPres
}
manifest_text += _get_application_tag(Ref<EditorExportPlatform>(this), p_preset, _has_read_write_storage_permission(perms), p_debug, manifest_metadata);
manifest_text += "</manifest>\n";
String manifest_path = ExportTemplateManager::get_android_build_directory(p_preset).path_join(vformat("src/%s/AndroidManifest.xml", (p_debug ? "debug" : "release")));
@@ -1955,6 +1972,12 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
if (int(p_preset->get("gradle_build/export_format")) == EXPORT_FORMAT_AAB && !gradle_build_enabled) {
return TTR("\"Export AAB\" is only valid when \"Use Gradle Build\" is enabled.");
}
} else if (p_name == "gradle_build/google_play_instant") {
bool instant_enabled = p_preset->get("gradle_build/google_play_instant");
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
if (instant_enabled && !gradle_build_enabled) {
return TTR("\"Instant Build\" is only valid when \"Use Gradle Build\" is enabled.");
}
} else if (p_name == "gradle_build/min_sdk") {
String min_sdk_str = p_preset->get("gradle_build/min_sdk");
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
@@ -2022,6 +2045,7 @@ void EditorExportPlatformAndroid::get_export_options(List<ExportOption> *r_optio
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/gradle_build_directory", PROPERTY_HINT_PLACEHOLDER_TEXT, "res://android"), "", false, false));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/android_source_template", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "gradle_build/export_format", PROPERTY_HINT_ENUM, "Export APK,Export AAB"), EXPORT_FORMAT_APK, false, true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "gradle_build/google_play_instant"), false, true, true));
// Using String instead of int to default to an empty string (no override) with placeholder for instructions (see GH-62465).
// This implies doing validation that the string is a proper int.
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/min_sdk", PROPERTY_HINT_PLACEHOLDER_TEXT, vformat("%d (default)", DEFAULT_MIN_SDK_VERSION)), "", false, true));
@@ -3494,6 +3518,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
String enabled_abi_string = join_abis(enabled_abis, "|", false);
String sign_flag = should_sign ? "true" : "false";
String zipalign_flag = "true";
String play_instant_flag = bool_to_string(p_preset->get("gradle_build/google_play_instant"));
Vector<String> android_libraries;
Vector<String> android_dependencies;
@@ -3568,6 +3593,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
cmdline.push_back("-Pplugins_maven_repos=" + combined_android_dependencies_maven_repos); // argument to specify the list of maven repos for android dependencies provided by plugins.
cmdline.push_back("-Pperform_zipalign=" + zipalign_flag); // argument to specify whether the build should be zipaligned.
cmdline.push_back("-Pperform_signing=" + sign_flag); // argument to specify whether the build should be signed.
cmdline.push_back("-Pplay_instant_app=" + play_instant_flag); // argument to specify whether the build is for Google Play Instant.
// NOTE: The release keystore is not included in the verbose logging
// to avoid accidentally leaking sensitive information when sharing verbose logs for troubleshooting.