Skip to content

Commit 74eba7a

Browse files
committed
Revert the removal of the gradle_build/compress_native_libraries export option
1 parent 46c495c commit 74eba7a

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
@@ -2014,6 +2014,11 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
20142014
if (!enabled_deprecated_plugins_names.is_empty() && !gradle_build_enabled) {
20152015
return TTR("\"Use Gradle Build\" must be enabled to use the plugins.");
20162016
}
2017+
} else if (p_name == "gradle_build/compress_native_libraries") {
2018+
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
2019+
if (bool(p_preset->get("gradle_build/compress_native_libraries")) && !gradle_build_enabled) {
2020+
return TTR("\"Compress Native Libraries\" is only valid when \"Use Gradle Build\" is enabled.");
2021+
}
20172022
} else if (p_name == "gradle_build/export_format") {
20182023
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
20192024
if (int(p_preset->get("gradle_build/export_format")) == EXPORT_FORMAT_AAB && !gradle_build_enabled) {
@@ -2097,6 +2102,7 @@ void EditorExportPlatformAndroid::get_export_options(List<ExportOption> *r_optio
20972102
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "gradle_build/use_gradle_build"), false, true, true));
20982103
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/gradle_build_directory", PROPERTY_HINT_PLACEHOLDER_TEXT, "res://android"), "", false, false));
20992104
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "gradle_build/android_source_template", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
2105+
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "gradle_build/compress_native_libraries"), false, false, true));
21002106
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "gradle_build/export_format", PROPERTY_HINT_ENUM, "Export APK,Export AAB"), EXPORT_FORMAT_APK, false, true));
21012107
// Using String instead of int to default to an empty string (no override) with placeholder for instructions (see GH-62465).
21022108
// This implies doing validation that the string is a proper int.
@@ -3580,8 +3586,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
35803586
target_sdk_version = itos(DEFAULT_TARGET_SDK_VERSION);
35813587
}
35823588
String enabled_abi_string = join_abis(enabled_abis, "|", false);
3583-
String sign_flag = should_sign ? "true" : "false";
3589+
String sign_flag = bool_to_string(should_sign);
35843590
String zipalign_flag = "true";
3591+
String compress_native_libraries_flag = bool_to_string(p_preset->get("gradle_build/compress_native_libraries"));
35853592

35863593
Vector<String> android_libraries;
35873594
Vector<String> android_dependencies;
@@ -3656,6 +3663,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
36563663
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.
36573664
cmdline.push_back("-Pperform_zipalign=" + zipalign_flag); // argument to specify whether the build should be zipaligned.
36583665
cmdline.push_back("-Pperform_signing=" + sign_flag); // argument to specify whether the build should be signed.
3666+
cmdline.push_back("-Pcompress_native_libraries=" + compress_native_libraries_flag); // argument to specify whether the build should compress native libraries.
36593667

36603668
// NOTE: The release keystore is not included in the verbose logging
36613669
// 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
@@ -132,6 +132,14 @@ android {
132132
doNotStrip '**/*.so'
133133
}
134134

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