Skip to content

Commit 29ff6c3

Browse files
committed
Merge pull request #107681 from m4gr3d/revert_remove_compress_native_lib_option
Revert the removal of the `gradle_build/compress_native_libraries` export option
2 parents ca45211 + 74eba7a commit 29ff6c3

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

platform/android/doc_classes/EditorExportPlatformAndroid.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<member name="gradle_build/android_source_template" type="String" setter="" getter="">
5353
Path to a ZIP file holding the source for the export template used in a Gradle build. If left empty, the default template is used.
5454
</member>
55+
<member name="gradle_build/compress_native_libraries" type="bool" setter="" getter="">
56+
If [code]true[/code], native libraries are compressed when performing a Gradle build.
57+
[b]Note:[/b] While enabling compression can reduce the size of the binary, it may result in slower application startup because the native libraries must be extracted before use, rather than being loaded directly.
58+
If you're distributing your app via the Play Store, it's generally recommended to keep this option [code]false[/code], see [url=https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs]official documentation[/url].
59+
</member>
5560
<member name="gradle_build/custom_theme_attributes" type="Dictionary" setter="" getter="">
5661
A dictionary of custom theme attributes to include in the exported Android project. Each entry defines a theme attribute name and its value, and will be added to the [b]GodotAppMainTheme[/b].
5762
For example, the key [code]android:windowSwipeToDismiss[/code] with the value [code]false[/code] is resolved to [code]&lt;item name="android:windowSwipeToDismiss"&gt;false&lt;/item&gt;[/code].

platform/android/export/export_plugin.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,11 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
20312031
if (!enabled_deprecated_plugins_names.is_empty() && !gradle_build_enabled) {
20322032
return TTR("\"Use Gradle Build\" must be enabled to use the plugins.");
20332033
}
2034+
} else if (p_name == "gradle_build/compress_native_libraries") {
2035+
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
2036+
if (bool(p_preset->get("gradle_build/compress_native_libraries")) && !gradle_build_enabled) {
2037+
return TTR("\"Compress Native Libraries\" is only valid when \"Use Gradle Build\" is enabled.");
2038+
}
20342039
} else if (p_name == "gradle_build/export_format") {
20352040
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
20362041
if (int(p_preset->get("gradle_build/export_format")) == EXPORT_FORMAT_AAB && !gradle_build_enabled) {
@@ -2114,6 +2119,7 @@ void EditorExportPlatformAndroid::get_export_options(List<ExportOption> *r_optio
21142119
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "gradle_build/use_gradle_build"), false, true, true));
21152120
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/gradle_build_directory", PROPERTY_HINT_PLACEHOLDER_TEXT, "res://android"), "", false, false));
21162121
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/android_source_template", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
2122+
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "gradle_build/compress_native_libraries"), false, false, true));
21172123
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "gradle_build/export_format", PROPERTY_HINT_ENUM, "Export APK,Export AAB"), EXPORT_FORMAT_APK, false, true));
21182124
// Using String instead of int to default to an empty string (no override) with placeholder for instructions (see GH-62465).
21192125
// This implies doing validation that the string is a proper int.
@@ -3691,8 +3697,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
36913697
target_sdk_version = itos(DEFAULT_TARGET_SDK_VERSION);
36923698
}
36933699
String enabled_abi_string = join_abis(enabled_abis, "|", false);
3694-
String sign_flag = should_sign ? "true" : "false";
3700+
String sign_flag = bool_to_string(should_sign);
36953701
String zipalign_flag = "true";
3702+
String compress_native_libraries_flag = bool_to_string(p_preset->get("gradle_build/compress_native_libraries"));
36963703

36973704
Vector<String> android_libraries;
36983705
Vector<String> android_dependencies;
@@ -3767,6 +3774,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
37673774
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.
37683775
cmdline.push_back("-Pperform_zipalign=" + zipalign_flag); // argument to specify whether the build should be zipaligned.
37693776
cmdline.push_back("-Pperform_signing=" + sign_flag); // argument to specify whether the build should be signed.
3777+
cmdline.push_back("-Pcompress_native_libraries=" + compress_native_libraries_flag); // argument to specify whether the build should compress native libraries.
37703778

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

platform/android/java/app/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ android {
134134
}
135135
}
136136

137+
jniLibs {
138+
// Setting this to true causes AGP to package compressed native libraries when building the app
139+
// For more background, see:
140+
// - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
141+
// - https://stackoverflow.com/a/44704840
142+
useLegacyPackaging shouldUseLegacyPackaging()
143+
}
144+
137145
// Always select Godot's version of libc++_shared.so in case deps have their own
138146
pickFirst 'lib/x86/libc++_shared.so'
139147
pickFirst 'lib/x86_64/libc++_shared.so'

platform/android/java/app/config.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ ext.shouldNotStrip = { ->
375375
return isAndroidStudio() || project.hasProperty("doNotStrip")
376376
}
377377

378+
/**
379+
* Whether to use the legacy convention of compressing all .so files in the APK.
380+
*
381+
* For more background, see:
382+
* - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
383+
* - https://stackoverflow.com/a/44704840
384+
*/
385+
ext.shouldUseLegacyPackaging = { ->
386+
String legacyPackagingFlag = project.hasProperty("compress_native_libraries") ? project.property("compress_native_libraries") : ""
387+
if (legacyPackagingFlag != null && !legacyPackagingFlag.isEmpty()) {
388+
return Boolean.parseBoolean(legacyPackagingFlag)
389+
}
390+
391+
// Default behavior for minSdk >= 24
392+
return false
393+
}
394+
378395
ext.getAddonsDirectory = { ->
379396
String addonsDirectory = project.hasProperty("addons_directory") ? project.property("addons_directory") : ""
380397
return addonsDirectory

0 commit comments

Comments
 (0)