Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android exports with Use Gradle Build create larger outputs #78780

Closed
DexterFstone opened this issue Jun 28, 2023 · 20 comments · Fixed by #88385
Closed

Android exports with Use Gradle Build create larger outputs #78780

DexterFstone opened this issue Jun 28, 2023 · 20 comments · Fixed by #88385

Comments

@DexterFstone
Copy link

Godot version

4.0.3 stable

System information

Windows 10, OpenGL 3.3

Issue description

Hi
when I export my project, my export file is 100MB, after using a custom template my apk file becomes 30MB, but when use Gradle build it's become 100mb again, why? it is a bug or can not have both?

Steps to reproduce

  1. Build a custom template
  2. Install the Android build template
  3. Add Android export
  4. Add your path of the custom template
  5. check using gradle build
  6. export

Minimal reproduction project

N/A

@DexterFstone DexterFstone changed the title Android export with Use Gradle Build and Custom Template Android export with Use Gradle Build and Custom Template problem Jun 28, 2023
@Calinou
Copy link
Member

Calinou commented Jun 28, 2023

Are you building an AAB with the Gradle build? If so, it's expected to be larger as it contains binaries for all architectures (rather than a single architecture in the APK as you've probably configured in the Android export preset).

@Calinou Calinou changed the title Android export with Use Gradle Build and Custom Template problem Android exports with Use Gradle Build create larger outputs Jun 28, 2023
@akien-mga
Copy link
Member

How do you set up the custom template? The custom Release and Debug template fields are prebuilt APKs, and thus only used for APK export (not Gradle builds).

For a custom Gradle build, you should reinstall the source template that you compiled yourself. I don't remember if there's an option for a custom source template in the preset or if you should unzip it manually in your project's res://android folder.

@DexterFstone
Copy link
Author

Are you building an AAB with the Gradle build?

APK v7 and v8

@akien-mga
Copy link
Member

docs.godotengine.org/en/stable/contributing/development/compiling/compiling_for_android.html

That page seems slightly outdated (or more like it lacks important information on the Gradle build source template).

When you compiled from source, it should have generated bin/android_source.zip.

Then you should remove any existing res://android folder, and reinstall the source template using that self-compiled zip.

You can do that by unzipping it manually as res://android/build, or copying bin/android_source.zip to the templates folder as described in that page, or use the "Install from File" option from that dialog if it shows up when pressing "Install Android Build Template..."

image

@DexterFstone
Copy link
Author

docs.godotengine.org/en/stable/contributing/development/compiling/compiling_for_android.html

That page seems slightly outdated (or more like it lacks important information on the Gradle build source template).

When you compiled from source, it should have generated bin/android_source.zip.

Then you should remove any existing res://android folder, and reinstall the source template using that self-compiled zip.

You can do that by unzipping it manually as res://android/build, or copying bin/android_source.zip to the templates folder as described in that page, or use the "Install from File" option from that dialog if it shows up when pressing "Install Android Build Template..."

image

tnx but I get an error
image

@akien-mga
Copy link
Member

To be sure, can you check which version of Godot you compiled from source?

You mentioned using Godot 4.0.3.stable, so you need to make sure that the custom Android template that you compile is for that same version, otherwise it can lead to compilation errors like this.

The error could also be something else of course, CC @m4gr3d who might have more insights.

@DexterFstone
Copy link
Author

To be sure, can you check which version of Godot you compiled from source?

My Godot 4.0.3
My Godot source is 4.0.3 and everything needed for export is 4.0.3

@DexterFstone
Copy link
Author

To be sure, can you check which version of Godot you compiled from source?

You mentioned using Godot 4.0.3.stable, so you need to make sure that the custom Android template that you compile is for that same version, otherwise it can lead to compilation errors like this.

The error could also be something else of course, CC @m4gr3d who might have more insights.

`# Generated using https://godot-build-options-generator.github.io

disable_3d = "yes"
optimize = "size"
minizip = "no"
module_basis_universal_enabled = "no"
module_bmp_enabled = "no"
module_bullet_enabled = "no"
module_camera_enabled = "no"
module_csg_enabled = "no"
module_dds_enabled = "no"
module_enet_enabled = "no"
module_gdnative_enabled = "no"
module_gltf_enabled = "no"
module_gridmap_enabled = "no"
module_hdr_enabled = "no"
module_jpg_enabled = "no"
module_meshoptimizer_enabled = "no"
module_minimp3_enabled = "no"
module_mobile_vr_enabled = "no"
module_navigation_enabled = "no"
module_multiplayer_enabled = "no"
module_noise_enabled = "no"
module_ogg_enabled = "no"
module_opensimplex_enabled = "no"
module_openxr_enabled = "no"
module_opus_enabled = "no"
module_pvr_enabled = "no"
module_regex_enabled = "no"
module_stb_vorbis_enabled = "no"
module_svg_enabled = "no"
module_tga_enabled = "no"
module_theora_enabled = "no"
module_upnp_enabled = "no"
module_vhacd_enabled = "no"
module_visual_script_enabled = "no"
module_vorbis_enabled = "no"
module_webm_enabled = "no"
module_webrtc_enabled = "no"
module_websocket_enabled = "no"
module_webxr_enabled = "no"
`
this is my custom.py, can this make a problem?

@BITQinDynasty
Copy link

I encoutered the same problem. My source code version is 4.1.1.rc and I build android release template myself with and disable_3d=yes. the generated android_release.apk and android_source.zip are all around 30MB.
1, when "use gradle build" is disabled, the output apk size is 16MB.
2, when "use gradle build" is enabled and "export format" is apk, the output apk size is 48MB
3, when "use gradle build" is enabled and "export format" is aab, the output aab size is 16MB again.
Can anyone figure out why this happen?

@DexterFstone
Copy link
Author

DexterFstone commented Jul 16, 2023

today I export Android with Godot v4.1 and the file size is 38MB but when using gradle build it enables the size to go up to 121MB why size is so big?
as I remember in Godot 3.5 both export file size is the same (26MB <-> 36MB)

@LegatusMarcus
Copy link

LegatusMarcus commented Aug 9, 2023

@BITQinDynasty I'm used this tweak, and it's shrink to 20.5mb (with custom android source).

UPD: But, this crash the game, because of null pointer dereference.
UPD2: Nevermind, looks like it's a problem in my custom android source. Gonna to work this out.
UPD3: With default android build template and set android:extractNativeLibs="true" we get 28.1mb opposite to 67.5mb.

@54cz
Copy link

54cz commented Oct 20, 2023

android:extractNativeLibs="true"

@BITQinDynasty我使用了这个调整,它缩小到 20.5mb(使用自定义 android 源)。

UPD:但是,由于空指针取消引用,这会导致游戏崩溃。 UPD2:没关系,看起来这是我的自定义 Android 源中的问题。要去解决这个问题。 UPD3:使用默认的 android 构建模板并设置 android:extractNativeLibs="true" 我们得到 28.1mb,与 67.5mb 相反。

Adding Android: extractNativeLibs="true" has solved the problem, and I hope the default template can be added

@m4gr3d
Copy link
Contributor

m4gr3d commented Feb 13, 2024

@DexterFstone Can you use the Android Studio apk analyser to check what the generated apk contains.

@DexterFstone
Copy link
Author

android:extractNativeLibs="true"

@BITQinDynasty我使用了这个调整,它缩小到 20.5mb(使用自定义 android 源)。
UPD:但是,由于空指针取消引用,这会导致游戏崩溃。 UPD2:没关系,看起来这是我的自定义 Android 源中的问题。要去解决这个问题。 UPD3:使用默认的 android 构建模板并设置 android:extractNativeLibs="true" 我们得到 28.1mb,与 67.5mb 相反。

Adding Android: extractNativeLibs="true" has solved the problem, and I hope the default template can be added

solved

@akien-mga
Copy link
Member

Should we consider enabling this option by default @m4gr3d ?

@akien-mga akien-mga reopened this Feb 14, 2024
@m4gr3d
Copy link
Contributor

m4gr3d commented Feb 14, 2024

Should we consider enabling this option by default @m4gr3d ?

There are tradeoffs in doing so, notably slower app load time

Although your APK might be larger, your application loads faster because the libraries load directly from the APK at runtime.

https://developer.android.com/guide/topics/manifest/application-element#extractNativeLibs

https://developer.android.com/build/releases/past-releases/agp-4-2-0-release-notes#compress-native-libs-dsl

@scgm0
Copy link
Contributor

scgm0 commented Feb 14, 2024

Should we consider enabling this option by default @m4gr3d ?

There are tradeoffs in doing so, notably slower app load time

Although your APK might be larger, your application loads faster because the libraries load directly from the APK at runtime.

https://developer.android.com/guide/topics/manifest/application-element#extractNativeLibs

https://developer.android.com/build/releases/past-releases/agp-4-2-0-release-notes#compress-native-libs-dsl

But now that the option is enabled in template, why is it not enabled in Gradle build?

@m4gr3d
Copy link
Contributor

m4gr3d commented Feb 16, 2024

@scgm0 What's the minSdk value you set when using the gradle build?

@m4gr3d
Copy link
Contributor

m4gr3d commented Feb 16, 2024

But now that the option is enabled in template, why is it not enabled in Gradle build?

The reason for it is that android:extractNativeLibs=true used to be the default behavior up until api 23. So apks compiled with minSdk < 23 default to that and have their native libraries compressed, while apks with minSdk >= 23 have their native libraries uncompressed by default.

The minimum sdk we support is 21. As such the template apks are generated with android:extractNativeLibs=true automatcially.
The gradle build on the other hand has a default min sdk of 24 (for proper vulkan support), so android:extractNativeLibs is set to false for those builds.

@akien-mga akien-mga added this to the 4.3 milestone Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment