Michel Feinstein
Michel Feinstein

Reputation: 14296

Splash Screen triggers Resources$NotFoundException only on Android 8.1

I followed this tutorial here step by step, it works fine on my API 21 emulator, but on my 27 it crashes as soon as the app loads with:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.myapp/com.myapp.myapp.ui.SplashScreenActivity}: android.content.res.Resources$NotFoundException: Drawable com.myapp.myapp:drawable/splash_screen_background with resource ID #0x7f0700a9

My file drawable/splash_screen_background is this one:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:type="radial"
                android:gradientRadius="100%p"
                android:startColor="@color/primaryColor"
                android:endColor="@color/primaryDarkColor"/>
        </shape>
    </item>

    <item>
        <bitmap
        android:gravity="center"
            android:src="@drawable/ic_home_white_24dp"/>
    </item>
</layer-list>

I tried to use app:srcCompat, pass the drawable directly to the item eliminating the bitmap, but the problem persists. I have seen some people saying to use android:drawable= instead, but they say this crashes on < API 21.

This answer shows some pretty complicated extra configurations, including gradle options, I am not sure how this will impact my app, does it change the performance of vector graphics?

What's the right way to handle a layer-list on Android that will work on several APIs?

Upvotes: 4

Views: 1621

Answers (2)

ddoo
ddoo

Reputation: 2266

The tutorial you linked posted updated steps to account for vector drawables

The original blog post was created before vector resources were available on Android so all of the launcher icons are images, meaning no error is thrown by the tag.

Fixing this for apps with vector launcher icons requires deleting the tag and moving the drawable and gravity attributes to the tag.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@color/gray"/>
    <item
        android:drawable="@mipmap/ic_launcher_round"
        android:gravity="center"/>
</layer-list>

Upvotes: 1

pSych0
pSych0

Reputation: 81

Like you have suggested in your comment, the solution to the problem is, that your resources are not in the drawable folder.

All your drawable resource files should be in "drawable" too. If you have special features for higher android versions, you can uploaded files in "drawable-v21", "drawable-v24", ...

I hope that will help, i had the same problem and after putting every resource from different drawable folder in the global drawable folder, my problem was solved.

Upvotes: 0

Related Questions