Previously I was building and running a Flutter app fine. I don't remember making any change, but recently, I run into such errors while building and running the app on a smartphone through Android Studio:
Launching lib\main.dart on SM N900 in debug mode...
Running Gradle task 'assembleDebug'...
E/AndroidRuntime(12731): FATAL EXCEPTION: main
E/AndroidRuntime(12731): Process: io.flutter.demo.gallery, PID: 12731
E/AndroidRuntime(12731): java.lang.RuntimeException: Unable to start activity ComponentInfo{io.flutter.demo.gallery/io.flutter.demo.gallery.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable-v21/launch_background.xml from drawable resource ID #0x7f040000
E/AndroidRuntime(12731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
E/AndroidRuntime(12731): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
E/AndroidRuntime(12731): at android.app.ActivityThread.access$900(ActivityThread.java:177)
E/AndroidRuntime(12731): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
E/AndroidRuntime(12731): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(12731): at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime(12731): at android.app.ActivityThread.main(ActivityThread.java:5942)
E/AndroidRuntime(12731): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(12731): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(12731): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
E/AndroidRuntime(12731): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
E/AndroidRuntime(12731): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/launch_background.xml from drawable resource ID #0x7f040000
E/AndroidRuntime(12731): at android.content.res.Resources.loadDrawableForCookie(Resources.java:3752)
E/AndroidRuntime(12731): at android.content.res.Resources.loadDrawable(Resources.java:3620)
E/AndroidRuntime(12731): at android.content.res.Resources.getDrawable(Resources.java:1852)
E/AndroidRuntime(12731): at android.content.res.Resources.getDrawable(Resources.java:1818)
E/AndroidRuntime(12731): at io.flutter.embedding.android.FlutterActivity.getSplashScreenFromManifest(FlutterActivity.java:495)
E/AndroidRuntime(12731): at io.flutter.embedding.android.FlutterActivity.provideSplashScreen(FlutterActivity.java:469)
E/AndroidRuntime(12731): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onCreateView(FlutterActivityAndFragmentDelegate.java:301)
E/AndroidRuntime(12731): at io.flutter.embedding.android.FlutterActivity.createFlutterView(FlutterActivity.java:520)
E/AndroidRuntime(12731): at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:414)
E/AndroidRuntime(12731): at android.app.Activity.performCreate(Activity.java:6283)
E/AndroidRuntime(12731): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
E/AndroidRuntime(12731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
E/AndroidRuntime(12731): ... 10 more
E/AndroidRuntime(12731): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable
E/AndroidRuntime(12731): at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:202)
E/AndroidRuntime(12731): at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:147)
E/AndroidRuntime(12731): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150)
E/AndroidRuntime(12731): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1063)
E/AndroidRuntime(12731): at android.content.res.Resources.loadDrawableForCookie(Resources.java:3736)
E/AndroidRuntime(12731): ... 21 more
Flutter doctor
The output of flutter doctor -v
is:
>flutter doctor -v
[√] Flutter (Channel master, 1.24.0-8.0.pre.1, on Microsoft Windows [Version 10.0.19041.264], locale en-US)
• Flutter version 1.24.0-8.0.pre.1 at C:\Users\m3\repos\flutter
• Framework revision e444b1e3fa (5 weeks ago), 2020-10-30 00:41:52 -0400
• Engine revision 99cc50dfff
• Dart version 2.11.0 (build 2.11.0-266.0.dev)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at C:\Users\m3\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 50.0.1
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (3 available)
• SM N900 (mobile) • 4d00b6ae472d80eb • android-arm • Android 5.0 (API 21)
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.66
• No issues found!
I just simply Git checkout master branch. Open Android Studio. Connect the Android smartphone device to computer through USB port. Click the green triangle button (Android Studio) to build and run the app on the device with Android 5.0. Error are thrown on terminal. I'm on Windows 10.
Note Such posts show that maybe the Gradle build system needs to be configured differently, not sure how:
https://stackoverflow.com/a/39419701/3405291
Android Studio File > Invalidate Caches / Restart...
did NOT resolve the issue.
Building and running the app with Android 9 (API 28), the exception is resolved and the app is fine:
$ flutter doctor -v
[√] Flutter (Channel master, 1.26.0-2.0.pre.401, on Microsoft Windows [Version 10.0.19041.264], locale en-US)
• Flutter version 1.26.0-2.0.pre.401 at C:\Users\m3\repos\flutter
• Framework revision da5a454d5c (11 hours ago), 2021-01-17 01:24:03 -0500
• Engine revision 609036f2bf
• Dart version 2.12.0 (build 2.12.0-236.0.dev)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at C:\Users\m3\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 50.0.1
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (2 available)
• SM A105F (mobile) • RF8M60PVD5F • android-arm • Android 9 (API 28)
• Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88
• No issues found!
Implication so far is that the app runs fine with Android 9 (API 28) but throws the above-mentioned exception with Android 5.0 (API 21). Does anybody know what could be the problem cause? How could I possibly run the app on Android 5.0 (API 21)?
This is relevant:
https://github.com/flutter/gallery/issues/383
Also, this is relevant:
https://github.com/flutter/flutter/issues/73118
In file android\app\src\main\res\drawable-v21\launch_background.xml, the exception can be solved by replacing
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
by
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
In file android/app/src/main/AndroidManifest.xml
, the exception is resolved by commenting out this:
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
Removing the above resolves the exception, although I'm not sure if it has any side effect.
Original answer found here : Splash screen error: android.content.res.Resources$NotFoundException: Drawable
This issue happens most of the times when you include images from directory other than drawable. For eg:
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/image" />
</item>
Just use a image from drawable and you will get rid of the error.
In my case what solved this issue was copying the file launch_background.xml
, where my project's launch image and background color are specified, from:
project\android\app\src\main\res\drawable
into:
project\android\app\src\main\res\drawable-v21
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With