New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 912804 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 1
Type: Bug



Sign in to add a comment

Monochrome as a bundle is larger than Monochrome as an apk

Project Member Reported by agrieve@chromium.org, Dec 7

Issue description

Comparing these two files:
gs://chrome-signed/android-B0urB0N/72.0.3626.8/arm/MonochromeStable.apk
gs://chrome-signed/android-B0urB0N/72.0.3626.8/arm/MonochromeStable.apks

base-master.apk (within .apks) is 69042017 bytes.
Monochrome.apk is 68706080 bytes.
335937 bytes larger.

Looking at "Breakdown" stats from resource_sizes.py on both files:
* Java code size: 3342046 vs 3366340 
  * 24294 larger - expected from play core library.
* Non-compiled Android resources size: 339921 vs 473820
  * 133899 larger
  * Looks like res/**/*.xml files are larger. 
  * My guess is it's not using --no-xml-namespaces flag like we do for the apk.
    * See 69007c4049a6640493175997b6d915ddbfa58ed6
* Compiled Android resources (.arsc file): 5095200 vs 5271952
  * 176752 larger
  * Looks like names are not stripped
  * My guess is it's not using --enable-resource-obfuscation
    * See e734bc5eb8b08668196b95a9e38e6bea0773748c

Not sure if these are flags that we can pass to aapt ourselves, or if these need to be added to bundletool / play store?

 
Cc: mheikal@chromium.org
mheikal@ and me did some investigation into this.

Regarding the uncompressed resources:
We need some more investigation but the namespaces seems to be gone. Also, the res/ folders are much smaller for me:
APK: 10344
Base module: 10424
Maybe I'm doing something wrong.

Regarding the .arsc file:
Yeah, the names are not obfuscated. mheikal@ found out that there is a bug in aapt2 where optimizations are not applied building proto buffers.
By "uncompressed resources", do you mean "Non-compiled Android resources"? res/**/*.xml files are stored compressed :P.

What units are you using for res folders? 10344 bytes is way too small, but 10344kb is way to big :P

The --no-xml-namespaces is a part of aapt2 optimizations, so fingers crossed that the same bug is responsible for both.
Looking more, it's in kB I believe. I just uncompressed both APKs and measures the res/ folder size with du. That's probably not correct.

And, yeah, I mean the uncompiled resources.
For the resources.arsc bug, I have located and am working on a fix. 

For the non-compiled resources I have no idea why they are bigger. --no-xml-namespaces is not part of aapt2 optimize (it is part of link). But either way, there are no namespaces in the final binary xml (aapt dump xmltree does not show namespaces) so that is not the issue.
mheikal@ and me did some more research. The compiled XML files in the bundle contain the raw values. E.g. aapt dump xmltree <apk> res/anim/textbubble_in.xml gives

E: set (line=7)
  A: interpolator(0x01010141)=@0x10a000b (Raw: "@android:anim/linear_interpolator")
  A: duration(0x01010198)=@0x10e0000 (Raw: "@android:integer/config_shortAnimTime")
  E: alpha (line=11)
    A: fromAlpha(0x010101ca)=(type 0x4)0x0 (Raw: "0")
    A: toAlpha(0x010101cb)=(type 0x4)0x3f800000 (Raw: "1.0")
  E: translate (line=15)
    A: fromYDelta(0x010101c8)=(type 0x4)0xc1200000 (Raw: "-10")
    A: toYDelta(0x010101c9)=(type 0x4)0x0 (Raw: "0")

for the base module and

E: set (line=7)
  A: interpolator(0x01010141)=@0x10a000b
  A: duration(0x01010198)=@0x10e0000
  E: alpha (line=11)
    A: fromAlpha(0x010101ca)=(type 0x4)0x0
    A: toAlpha(0x010101cb)=(type 0x4)0x3f800000
  E: translate (line=15)
    A: fromYDelta(0x010101c8)=(type 0x4)0xc1200000
    A: toYDelta(0x010101c9)=(type 0x4)0x0

for the APK. Seems like the module is storing all raw values even though they are not needed.
Cc: -mheikal@chromium.org tiborg@chromium.org
Labels: -Pri-3 Pri-1
Owner: mheikal@chromium.org
Assigning to mheikal@ for now.
Ok the problem with resources.arsc is bigger than originally thought. The conversion between proto format resource table and binary format resource table is done by aapt2 but on play store's end (thus we do not control it). Looking at the code [1], if the proto format resource table contains all resources with the same name and type (because they are obfuscated), when the conversion occurs it would consider them all to be the same resource and fail.

The problem with bigger .xml files is also due to conversion. The conversion code [2] that outputs binary xml sets "keep_raw_values=true" thus the raw string values are kept for all attributes increasing file size. I am not sure why that is the case or what normally happens when there is no conversion necessary (when aapt2 directly outputs binary xml). I can look at this a bit more.

[1] https://cs.corp.google.com/pi-arc-dev/frameworks/base/tools/aapt2/format/proto/ProtoDeserialize.cpp?rcl=9d266a8609ebbee1fac932ad574ff7739d52b1ff&l=401
[2] https://cs.corp.google.com/pi-arc-dev/frameworks/base/tools/aapt2/cmd/Convert.cpp?rcl=9d266a8609ebbee1fac932ad574ff7739d52b1ff&l=142

Reminder M72 Stable is coming soon. Please review this bug and assess if this is indeed a RBS. If not, please remove the RBS label. If so, please make sure to land the fix and request a merge into the release branch ASAP. Thank you.
Labels: -M-72 M-73
Thanks for the reminder govind@, pushing this to RSB for M73, like many other things for bundles :-/

Comment 10 by agrieve@chromium.org, Yesterday (39 hours ago)

Labels: binary_size_team_q1_2019

Sign in to add a comment