Skip to content

Review SDK size: consider IL stripping #2074

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

Open
bruno-garcia opened this issue Mar 18, 2025 · 3 comments
Open

Review SDK size: consider IL stripping #2074

bruno-garcia opened this issue Mar 18, 2025 · 3 comments

Comments

@bruno-garcia
Copy link
Member

bruno-garcia commented Mar 18, 2025

We've received user feedback that the SDK is causing a significant increase of the final .apk.

@bitsandfoxes
Copy link
Contributor

Using Unity 6.0.43 I've come up with the following comparison when targeting Android:

| Variant                      | APK Size   | Extracted  | lib/       | res/      | smali/     | assets/   |
|:-----------------------------|:-----------|:-----------|:-----------|:----------|:-----------|:----------|
| test_with_sentry             |  19.56 MB  |  80.20 MB  |  52.18 MB  |  6.51 KB  |  18.34 MB  |  9.62 MB  |
| └─ arm64-v8a                 |            |            |            |           |            |           |
|    ├─ libil2cpp.so           |            |  37.90 MB  |            |           |            |           |
|    ├─ libmain.so             |            |   6.54 KB  |            |           |            |           |
|    ├─ libsentry-android.so   |            |  15.60 KB  |            |           |            |           |
|    ├─ libsentry.so           |            |   1.17 MB  |            |           |            |           |
|    └─ libunity.so            |            |  13.08 MB  |            |           |            |           |
| test_without_android_sdk     |  18.82 MB  |  72.96 MB  |  51.00 MB  |  6.51 KB  |  12.29 MB  |  9.62 MB  |
| └─ arm64-v8a                 |            |            |            |           |            |           |
|    ├─ libil2cpp.so           |            |  37.90 MB  |            |           |            |           |
|    ├─ libmain.so             |            |   6.54 KB  |            |           |            |           |
|    └─ libunity.so            |            |  13.08 MB  |            |           |            |           |
| test_without_sentry          |  15.14 MB  |  60.47 MB  |  40.36 MB  |  6.51 KB  |  12.29 MB  |  7.77 MB  |
| └─ arm64-v8a                 |            |            |            |           |            |           |
|    ├─ libil2cpp.so           |            |  28.21 MB  |            |           |            |           |
|    ├─ libmain.so             |            |   6.54 KB  |            |           |            |           |
|    └─ libunity.so            |            |  12.14 MB  |            |           |            |           |

Comparing the .apks, adding Sentry increases the size by ~4.42MB. A big contributer is the libil2cpp.so, which could be affected by changes to code stripping settings that we're preventing here:

[assembly: AlwaysLinkAssembly]

The increase in assets happens in assets/bin/Data/Managed/Metadata/global-metadata.dat.
The increase in smali happens in smali/io.sentry/.

@bruno-garcia
Copy link
Member Author

@bitsandfoxes said:

I think my comment on AlwaysLinkAssembly preventing code stripping is wrong/misleading. The attribute forces the linker to search the assembly and makes the stripper treat it as if it has been marked as root.
So code stripping should still take effect and do its thing.

@bitsandfoxes
Copy link
Contributor

bitsandfoxes commented May 9, 2025

In the table we see that the Android SDK does not actually add "that" much to the bundle size. I think I've narrowed down where the unexpected increase in size in libil2cpp.so is coming from.

Since there is limited dependency resolution for Unity packages, the SDK "deeply renames" its dependencies using a tool called "Assembly Alias". You can read more about how and why here.

But this means that in addition to the Unity/.NET SDK, C++ code gets generated for all its dependencies as well. Even if Unity or some other package would already bring them along.

We're now also setting the stripping level to High in CI for all Unity versions newer than 2019.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants