Splash Screen triggers Resources$NotFoundException only on Android 8.1

馋奶兔 提交于 2019-12-13 13:39:59

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/52527811/splash-screen-triggers-resourcesnotfoundexception-only-on-android-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!