Fix ResourceNotFound crash at launch on Android API 21#80707
Fix ResourceNotFound crash at launch on Android API 21#80707itsarjunsinh wants to merge 1 commit intoflutter:masterfrom itsarjunsinh:bugfix-api21-launch-crash
Conversation
Set background color in a <color> element. This prevents crash (#73118) caused by API 21 XML parser failing to parse a color as a drawable reference.
guidezpl
left a comment
There was a problem hiding this comment.
_ ___ _____ __ __
| | / __|_ _| \/ |
| |_| (_ | | | | |\/| |
|____\___| |_| |_| |_|
|
Although this PR fixes the crash, the root cause is likely in Flutter embedding package. The sample (flutter create) app will crash on Android 5.0. However, with a custom splash screen class the launch_background.xml works without a crash. Testable through AVD. LaunchActivity.kt package com.example.myapp
import android.app.Activity
import android.content.Intent
import android.os.Bundle
class LaunchActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:label="myapp"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".LaunchActivity"
android:theme="@style/LaunchTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Removed the intent filter -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Disabled the SplashScreenDrawable -->
<!--<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>-->
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest> |
|
Friendly ping @xster , could you take a look at this too? |
|
FYI @zanderso |
They indeed work but without respecting the system-wide light/dark theme as intended by #65182. The original xml is technically valid. Unsure what to test. @Hixie? |
|
Ideally we would have a test that launches and Android app running on API 21. |
|
Yeah, ideally we'd test with different versions of Android, or something like that. Failing that, maybe we can check that when you do |
|
@itsarjunsinh are you still working on this? |
|
@jonahwilliams This PR would've only resolved the problem in new projects. So, I looked into the engine and embedding package and have a fix for all affected projects. I'll close this PR. New PR: flutter/engine#26083 |
Fixes #73118 & #65447, prevents crashes on Android API 21 devices at launch from failing to parse a color as drawable reference for the splash screen.
Instead of assigning "?colorBackground" in android:drawable attribute of
<item>element of the splash screen, it is assigned in a new child<color>element.This is because the XML parser in Android 5.0 doesn't parse a color as a drawable reference.For an unknown Flutter specific splash screen implementation bug, the parsing doesn't happen. A custom splash screen class with the existing launch_background.xml doesn't cause a crash.Since Flutter 2.0.0, this bug has been in the stable channel. All projects with the launch_background.xml from PR #65182 & #69255 including the base starter project are/were affected.
This change doesn't affect API level < 21.
Pre-launch Checklist
///).