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

fix apk total size calculation #18

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Conversation

0xera
Copy link
Contributor

@0xera 0xera commented Jan 17, 2025

I have found that the APK's total size is incorrect and does not match what Android Studio is showing.

val total =
resourceDownloadSize + nativeLibDownloadSize + assetDownloadSize + otherDownloadSize + classDownloadSize
resourceDownloadSize + nativeLibDownloadSize + assetDownloadSize + otherDownloadSize + dexDownloadFile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @0xera, thank a lot for reporting and fixing the issues.
By right, the classDownloadSize should ~equal to the dexDownloadFile. A small different might be because this calculation:

classes = classes.map { it.copy(downloadSize = (it.size * ratio).toLong()) }.toSet()

Was your project's result largely the difference between Android Studio vs App-sizer report?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. As the size of the application increases, I get more and more different results.

(Before and after fix)

Download size:

  • App Sizer sample:
    • AAB mode:
      | apk | 3.941 MB | 3.944 MB
      Screenshot 2025-01-23 at 13 01 31
    • APK mode:
      | apk | 4.097 MB | 4.100 MB
      Screenshot 2025-01-23 at 12 58 45
  • My app (APK mode):
    | apk | 13.765 MB | 13.778 MB
    Screenshot 2025-01-23 at 13 21 34
  • Another my app (APK mode):
    | apk | 108.818 MB | 108.865 MB
    Screenshot 2025-01-23 at 12 47 44

Raw Size:

  • App Sizer sample:
    • AAB mode:
      | apk | 4.240 MB | 4.255 MB
      Screenshot 2025-01-23 at 13 01 31
    • APK mode:
      | apk | 4.665 MB | 5.061 MB
      Screenshot 2025-01-23 at 12 58 45
  • My app (APK mode):
    | apk | 21.469 MB | 39.966 MB
    Screenshot 2025-01-23 at 13 21 34

As you can see, the dexes size calculation is more correct for the size of the downloadable apk (especially for large apk files) and corrects the calculation of the raw size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me share a bit of context. As I shared in this document https://grab.github.io/app-sizer/limitation/#class-download-size-calculation

class's download size = class raw size * (dex download size / all classes' raw size)
-> Sum (classes download size ) = (sum(class raw size) * dex download size) / all classes' raw size = dex download size

But there is some minor difference due to the rounded number & floating point number on the calculation.
Anyway, if this helps to have a closer number to the Android Studio report. Let merge
Thanks for contributing

@akshay-grabtaxi akshay-grabtaxi merged commit 26a0a97 into grab:master Jan 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants