After integrating App-Bundle into my professional app I faced many issues through Crashlytics about the first screen of the app when inflating an ImageView.
This is the ResourceNotFoundException.
Caused by: android.view.InflateException: Binary XML file line #48: Binary XML file line #48: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #48: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f08009d
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f08009d
at android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:242)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:739)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:609)
at android.content.res.Resources.loadDrawable(Resources.java:885)
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.widget.ImageView.<init>(ImageView.java:188)
at android.widget.ImageView.<init>(ImageView.java:171)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:187)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1267)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1317)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:470)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:141)
at io.example.SplashScreen.onCreate(SplashScreenActivity.kt:50)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
2019-03-11 12:13:52.605 14143-14143/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Of course I couldn't reproduce at the beginning then I made many attempts with bundletool. I've seen similar threads but not digging the issue enough.
I figured out that generating an apk from the bundle with a lower density could reproduce the crash.
With my attempt I extracted Nexus6P specs as following
{
"supportedAbis": ["x86"],
"supportedLocales": ["en_US"],
"screenDensity": 560,
"sdkVersion": 26
}
Then I changed screenDensity to 320 or even 120 which makes the crash happen. Lookin' deeper at the *.apks generated file we have :
- base-en.apk
- base-ldpi.apk
- base-master.apk
I currently have mdpi/hdpi/xhdpi/xxhdpi/xxxhdpi folders.
I tried adding drawable-ldpi folder but in vain.
I checked in base-ldpi.apk to look after the resource not found, it is well present in the apk.
As a quick fix I can disable density splitting from gradle configuration or even turn off app bundle but I wish for a better ending.
Any idea ? Thank you :)