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

x/mobile: reduce size of generated artifacts #40348

Closed
ToJen opened this issue Jul 22, 2020 · 5 comments
Closed

x/mobile: reduce size of generated artifacts #40348

ToJen opened this issue Jul 22, 2020 · 5 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ToJen
Copy link

ToJen commented Jul 22, 2020

The size of Go builds can be shrunk with the ldflags build option like this:
go build -ldflags '-s -w' -o my_app.exe

This can be reduced further with UPX as such:
upx -o my_app_min.exe my_app.exe

More on this here.

I'm able to pass the ldflags into gomobile like this:
gomobile bind -ldflags '-s -w' -target=android github.com/my/app.

I would like to "inject" UPX somewhere in the bind process to reduce the size of my generated .aar and .framework.

A possible flow is this:

  1. Build: go build -ldflags '-s -w' -o my_app.exe
  2. Shrink: upx -o my_app_min.exe my_app.exe
  3. Pass into gomobile:gomobile bind --from-build=my_app_min.exe -target=android github.com/my/app
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 22, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 22, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 22, 2020
@toothrot
Copy link
Contributor

/cc @hyangah

@ToJen
Copy link
Author

ToJen commented Jul 24, 2020

@toothrot @hyangah what's a place to start the investigation. I believe many users will benefit from a smaller aar and framework. Would it make sense at all to achieve it this way?

@ToJen
Copy link
Author

ToJen commented Jul 24, 2020

@ToJen ToJen changed the title x/mobile: include UPX compression option between go build and bind x/mobile: reduce size of generated artifacts Aug 1, 2020
@BenLubar
Copy link

Another way to reduce the size of the APK would be to generate an AAB instead, which would mean an x86 device would only receive x86 code and an ARM device would only get ARM code.

As it currently stands, the APK contains 4 copies of all native code, which totals about 100 megabytes for my app after zip compression.

@ToJen
Copy link
Author

ToJen commented Sep 23, 2020

@BenLubar I came across this article which doesn't use gomobile. It may be possible to achieve my suggestions with the author's approach.

@ToJen ToJen closed this as completed Sep 23, 2020
@golang golang locked and limited conversation to collaborators Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants