Skip to content

Commit 12ad9ed

Browse files
committed
Add support for exporting to Google Play Instant
1 parent 4a44078 commit 12ad9ed

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

platform/android/doc_classes/EditorExportPlatformAndroid.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
<member name="gradle_build/export_format" type="int" setter="" getter="">
5656
Application export format (*.apk or *.aab).
5757
</member>
58+
<member name="gradle_build/google_play_instant" type="bool" setter="" getter="">
59+
If [code]true[/code], configures the exported project for Play Instant Build.
60+
Use this option when targeting Play Instant to allow users to launch the app without installation. See [url=https://developer.android.com/topic/google-play-instant/overview]Google Play Instant[/url].
61+
[b]Note:[/b] Instant play games also need to be optimized for size. See [url=https://docs.godotengine.org/en/stable/contributing/development/compiling/optimizing_for_size.html]Optimizing a build for size[/url].
62+
</member>
5863
<member name="gradle_build/gradle_build_directory" type="String" setter="" getter="">
5964
Path to the Gradle build directory. If left empty, then [code]res://android[/code] will be used.
6065
</member>

platform/android/export/export_plugin.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static const int EXPORT_FORMAT_AAB = 1;
280280

281281
static const char *APK_ASSETS_DIRECTORY = "assets";
282282
static const char *AAB_ASSETS_DIRECTORY = "assetPackInstallTime/src/main/assets";
283+
static const char *INSTANT_APP_ASSETS_DIRECTORY = "assets"; // instant build doesn't support installTime assetspacks, so using the same directory as APK
283284

284285
static const int DEFAULT_MIN_SDK_VERSION = 24; // Should match the value in 'platform/android/java/app/config.gradle#minSdk'
285286
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
524525

525526
String EditorExportPlatformAndroid::get_assets_directory(const Ref<EditorExportPreset> &p_preset, int p_export_format) const {
526527
String gradle_build_directory = ExportTemplateManager::get_android_build_directory(p_preset);
528+
529+
bool google_play_instant_build = p_preset->get("gradle_build/google_play_instant");
530+
if (google_play_instant_build) {
531+
return gradle_build_directory.path_join(INSTANT_APP_ASSETS_DIRECTORY); // Always use base APK asset format
532+
}
533+
527534
return gradle_build_directory.path_join(p_export_format == EXPORT_FORMAT_AAB ? AAB_ASSETS_DIRECTORY : APK_ASSETS_DIRECTORY);
528535
}
529536

@@ -993,10 +1000,19 @@ void EditorExportPlatformAndroid::_get_manifest_info(const Ref<EditorExportPrese
9931000

9941001
void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug) {
9951002
print_verbose("Building temporary manifest...");
1003+
1004+
bool google_play_instant_build = (bool)p_preset->get("gradle_build/google_play_instant");
1005+
9961006
String manifest_text =
9971007
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
9981008
"<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n"
999-
" xmlns:tools=\"http://schemas.android.com/tools\">\n";
1009+
" xmlns:tools=\"http://schemas.android.com/tools\"";
1010+
1011+
if (google_play_instant_build) {
1012+
manifest_text += " android:targetSandboxVersion=\"2\" \n xmlns:dist=\"http://schemas.android.com/apk/distribution\"";
1013+
}
1014+
1015+
manifest_text += ">\n";
10001016

10011017
manifest_text += _get_screen_sizes_tag(p_preset);
10021018
manifest_text += _get_gles_tag();
@@ -1030,6 +1046,7 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPres
10301046
}
10311047

10321048
manifest_text += _get_application_tag(Ref<EditorExportPlatform>(this), p_preset, _has_read_write_storage_permission(perms), p_debug, manifest_metadata);
1049+
10331050
manifest_text += "</manifest>\n";
10341051
String manifest_path = ExportTemplateManager::get_android_build_directory(p_preset).path_join(vformat("src/%s/AndroidManifest.xml", (p_debug ? "debug" : "release")));
10351052

@@ -1955,6 +1972,12 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
19551972
if (int(p_preset->get("gradle_build/export_format")) == EXPORT_FORMAT_AAB && !gradle_build_enabled) {
19561973
return TTR("\"Export AAB\" is only valid when \"Use Gradle Build\" is enabled.");
19571974
}
1975+
} else if (p_name == "gradle_build/google_play_instant") {
1976+
bool instant_enabled = p_preset->get("gradle_build/google_play_instant");
1977+
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
1978+
if (instant_enabled && !gradle_build_enabled) {
1979+
return TTR("\"Instant Build\" is only valid when \"Use Gradle Build\" is enabled.");
1980+
}
19581981
} else if (p_name == "gradle_build/min_sdk") {
19591982
String min_sdk_str = p_preset->get("gradle_build/min_sdk");
19601983
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
20222045
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/gradle_build_directory", PROPERTY_HINT_PLACEHOLDER_TEXT, "res://android"), "", false, false));
20232046
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/android_source_template", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
20242047
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "gradle_build/export_format", PROPERTY_HINT_ENUM, "Export APK,Export AAB"), EXPORT_FORMAT_APK, false, true));
2048+
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "gradle_build/google_play_instant"), false, true, true));
20252049
// Using String instead of int to default to an empty string (no override) with placeholder for instructions (see GH-62465).
20262050
// This implies doing validation that the string is a proper int.
20272051
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
34943518
String enabled_abi_string = join_abis(enabled_abis, "|", false);
34953519
String sign_flag = should_sign ? "true" : "false";
34963520
String zipalign_flag = "true";
3521+
String play_instant_flag = bool_to_string(p_preset->get("gradle_build/google_play_instant"));
34973522

34983523
Vector<String> android_libraries;
34993524
Vector<String> android_dependencies;
@@ -3568,6 +3593,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
35683593
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.
35693594
cmdline.push_back("-Pperform_zipalign=" + zipalign_flag); // argument to specify whether the build should be zipaligned.
35703595
cmdline.push_back("-Pperform_signing=" + sign_flag); // argument to specify whether the build should be signed.
3596+
cmdline.push_back("-Pplay_instant_app=" + play_instant_flag); // argument to specify whether the build is for Google Play Instant.
35713597

35723598
// NOTE: The release keystore is not included in the verbose logging
35733599
// to avoid accidentally leaking sensitive information when sharing verbose logs for troubleshooting.

platform/android/export/gradle_export_util.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform,
315315
int app_category_index = (int)(p_preset->get("package/app_category"));
316316
bool is_game = app_category_index == APP_CATEGORY_GAME;
317317

318+
bool google_play_instant_build = (bool)p_preset->get("gradle_build/google_play_instant");
319+
318320
String manifest_application_text = vformat(
319321
" <application android:label=\"@string/godot_project_name_string\"\n"
320322
" android:allowBackup=\"%s\"\n"
@@ -335,6 +337,10 @@ String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform,
335337
}
336338
manifest_application_text += " tools:ignore=\"GoogleAppIndexingWarning\">\n\n";
337339

340+
if (google_play_instant_build) {
341+
manifest_application_text += " <dist:module dist:instant=\"true\" />\n";
342+
}
343+
338344
for (int i = 0; i < p_metadata.size(); i++) {
339345
manifest_application_text += vformat(" <meta-data tools:node=\"replace\" android:name=\"%s\" android:value=\"%s\" />\n", p_metadata[i].name, p_metadata[i].value);
340346
}

platform/android/java/app/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ dependencies {
3737
implementation "androidx.fragment:fragment:$versions.fragmentVersion"
3838
implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
3939

40+
if (isInstantApp()) {
41+
implementation "com.google.android.gms:play-services-instantapps:$versions.instantAppsVersion"
42+
}
43+
4044
if (rootProject.findProject(":lib")) {
4145
implementation project(":lib")
4246
} else if (rootProject.findProject(":godot:lib")) {
@@ -90,7 +94,7 @@ android {
9094
jvmTarget = versions.javaVersion
9195
}
9296

93-
assetPacks = [":assetPackInstallTime"]
97+
assetPacks = isInstantApp() ? [] : [":assetPackInstallTime"]
9498

9599
namespace = 'com.godot.game'
96100

platform/android/java/app/config.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ ext.versions = [
1515
// Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
1616
ndkVersion : '28.1.13356709',
1717
splashscreenVersion: '1.0.1',
18-
openxrVendorsVersion: '4.0.0-stable'
18+
openxrVendorsVersion: '4.0.0-stable',
19+
instantAppsVersion: '17.0.0'
1920

2021
]
2122

@@ -379,3 +380,8 @@ ext.getAddonsDirectory = { ->
379380
String addonsDirectory = project.hasProperty("addons_directory") ? project.property("addons_directory") : ""
380381
return addonsDirectory
381382
}
383+
384+
ext.isInstantApp = { ->
385+
String instantApp = project.hasProperty("play_instant_app") ? project.property("play_instant_app") : ""
386+
return Boolean.parseBoolean(instantApp)
387+
}

0 commit comments

Comments
 (0)