google/bundletool

Unconsistant drawable resource packaging when DPI split is enabled.

ganadist opened this issue · 3 comments

Describe the bug

$ unzip -t app-production-release.aab | grep common_img_tooltip_arrow_
    testing: base/res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp   OK
    testing: base/res/drawable-xhdpi-v4/common_img_tooltip_arrow_up.webp   OK

$ bundletool build-apks --bundle=app-production-release.aab --output=out.apks

$ list.py out.apks
splits/base-hdpi.apk res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp
splits/base-master.apk res/drawable-xhdpi-v4/common_img_tooltip_arrow_up.webp
splits/base-tvdpi.apk res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp
splits/base-xhdpi.apk res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp
splits/base-xxhdpi.apk res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp
splits/base-xxxhdpi.apk res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp

common_img_tooltip_arrow_up.webp is included at splits/base-master.apk
But common_img_tooltip_arrow_down.webp is included at DPI split
Also, common_img_tooltip_arrow_down.webp is not included at splits/base-mdpi.apk and splits/base-ldpi.apk
So, app crashed by android.view.InflateException on ldpi/mdpi devices.

Bundletool version(s) affected
Version: Tested on 0.14.0, 1.8.2, 1.12.1, 1.13.2, 1.14.0

Stacktrace
N/A

To Reproduce

   |-  app
   |-  lib1
   |    |- src/main/res/drawable-xhdpi/common_img_tooltip_arrow_down.webp
   |    |- src/main/res/drawable-xhdpi/common_img_tooltip_arrow_up.webp
   |-  lib2
        |- src/main/res/values/ids.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
     <item name="common_img_tooltip_arrow_down" type="drawable"/>
</resources>

Expected behavior
res/drawable-xhdpi/common_img_tooltip_arrow_down.webp should be included at splits/base-master.apk
Or res/drawable-xhdpi/common_img_tooltip_arrow_down.webp should be included at all split dpi apks including ldpi and mdpi

Known workaround
Remove ids.xml under lib2

Environment:
OS: Any

Additional context
AppBundle file was generated by Android Gradle Plugin 7.2.2

$ bundletool dump resources --bundle=app-production-release.aab --resource=drawable/common_img_tooltip_arrow_down --values 
Package 'xxxxx':
0x7f0806f8 - drawable/common_img_tooltip_arrow_down
	(default) - [STR] ""
	density: 320 - [FILE] res/drawable-xhdpi-v4/common_img_tooltip_arrow_down.webp

$ bundletool dump resources --bundle=app-production-release.aab --resource=drawable/common_img_tooltip_arrow_up --values
Package 'xxxxx':
0x7f0806f9 - drawable/common_img_tooltip_arrow_up
	density: 320 - [FILE] res/drawable-xhdpi-v4/common_img_tooltip_arrow_up.webp

Sorry, missed this issue earlier. Any chance you still AAB file to reproduce this?

@ymakhno
Thank you for your interest.

I uploaded reproducible project

$ git clone https://github.com/ganadist/VersionCodeDemo -b bundletool_issue_318
$ cd VersionCodeDemo

$ ./gradlew :app:bundleDevelopDebug

$ ./build_apks.sh

Package 'com.example.myapplication':
0x7f070060 - drawable/img1
	density: 320 - [FILE] res/drawable-xhdpi-v4/img1.png

Package 'com.example.myapplication':
0x7f070061 - drawable/img2
	(default) - [STR] ""
	density: 320 - [FILE] res/drawable-xhdpi-v4/img2.png

tmp/splits/base-master.apk
    testing: res/drawable-xhdpi-v4/img1.png   OK

tmp/splits/base-hdpi.apk
    testing: res/drawable-xhdpi-v4/img2.png   OK

tmp/splits/base-ldpi.apk

tmp/splits/base-mdpi.apk

tmp/splits/base-tvdpi.apk
    testing: res/drawable-xhdpi-v4/img2.png   OK

tmp/splits/base-xhdpi.apk
    testing: res/drawable-xhdpi-v4/img2.png   OK

tmp/splits/base-xxhdpi.apk
    testing: res/drawable-xhdpi-v4/img2.png   OK

tmp/splits/base-xxxhdpi.apk
    testing: res/drawable-xhdpi-v4/img2.png   OK

In your setup you include img2 drawable resource into both lib1 and lib2 with some strange setup in lib2 in ids.xml. This setup causes img2 have two values: default empty value and xhdpi value. Default empty value in this case goes to main split and both ldpi and mdpi APKs rely on this value while hdpi+ APKs contain real drawable.

This is WAI.