Skip to content

Fix ResourceNotFound crash at launch on Android API 21 #80707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Fix ResourceNotFound crash at launch on Android API 21 #80707

wants to merge 1 commit into from

Conversation

itsarjunsinh
Copy link

@itsarjunsinh itsarjunsinh commented Apr 19, 2021

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.

Test device API Before fix After fix
Asus A450CG 21 Crash ✔️
Nexus 7 21 Crash ✔️
AVD 22 ✔️ ✔️
Asus Z010D 23 ✔️ ✔️
Asus A501CG 24 ✔️ ✔️
Poco F1 30 ✔️ ✔️

This change doesn't affect API level < 21.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

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.
@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 19, 2021
@google-cla google-cla bot added the cla: yes label Apr 19, 2021
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  _    ___ _____ __  __ 
 | |  / __|_   _|  \/  |
 | |_| (_ | | | | |\/| |
 |____\___| |_| |_|  |_|
                        

@itsarjunsinh
Copy link
Author

@blasten, @xster

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>

@jonahwilliams
Copy link
Contributor

Friendly ping @xster , could you take a look at this too?

@jonahwilliams
Copy link
Contributor

FYI @zanderso

@itsarjunsinh
Copy link
Author

@jonahwilliams
Copy link
Contributor

Ideally we would have a test that launches and Android app running on API 21.

@Hixie
Copy link
Contributor

Hixie commented Apr 29, 2021

Yeah, ideally we'd test with different versions of Android, or something like that.

Failing that, maybe we can check that when you do flutter create the XML file that's created has what we expect? Then in the test you can leave a big comment explaining why it's important, so that if someone tries to "fix" it, they'll at least know what to test for manually.

@jonahwilliams
Copy link
Contributor

@itsarjunsinh are you still working on this?

@itsarjunsinh
Copy link
Author

itsarjunsinh commented May 11, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android app fails to launch on API 21
5 participants