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

Comments

@ToJen
Copy link

@ToJen 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
@toothrot
Copy link
Contributor

@toothrot toothrot commented Jul 22, 2020

/cc @hyangah

@ToJen
Copy link
Author

@ToJen 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 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

@BenLubar BenLubar commented Sep 18, 2020

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 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 Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants