Flutter Canvas: trying to draw too large bitmap

45 views Asked by At

so I get this error when I try to launch my flutter app on one of my friends devices (Xiaomi poco, so far I only found this issue on this device, other new and old android devices work fine). What happens is that the screen turns off when launching the app, and when unlocking the screen I am still in the app and then it works fine.

Flutter doctor runs fine. Any ideas what could be the issue and how to fix it?

What I tried is compressing all of my splash.png images, but interestingly the error was exactly the same, it also read Canvas: trying to draw too large(107907360bytes) bitmap..

When the app starts, and after asking for some permissions from the user, images will be cached and shown in a ListView, maybe the issue is here?

The error is:

E/AndroidRuntime(13215): FATAL EXCEPTION: wmshell.splashscreen
E/AndroidRuntime(13215): Process: com.android.systemui, PID: 13215
E/AndroidRuntime(13215): java.lang.RuntimeException: Canvas: trying to draw too large(107907360bytes) bitmap.
E/AndroidRuntime(13215):    at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
E/AndroidRuntime(13215):    at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
E/AndroidRuntime(13215):    at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
E/AndroidRuntime(13215):    at android.view.View.getDrawableRenderNode(View.java:23653)
E/AndroidRuntime(13215):    at android.view.View.drawBackground(View.java:23574)
E/AndroidRuntime(13215):    at android.view.View.draw(View.java:23332)
E/AndroidRuntime(13215):    at android.view.View.updateDisplayListIfDirty(View.java:22201)
E/AndroidRuntime(13215):    at android.view.View.draw(View.java:23067)
E/AndroidRuntime(13215):    at android.view.ViewGroup.drawChild(ViewGroup.java:4543)
E/AndroidRuntime(13215):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4301)
E/AndroidRuntime(13215):    at android.view.View.updateDisplayListIfDirty(View.java:22190)
E/AndroidRuntime(13215):    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:682)
E/AndroidRuntime(13215):    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:690)
E/AndroidRuntime(13215):    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:795)
E/AndroidRuntime(13215):    at android.view.ViewRootImpl.draw(ViewRootImpl.java:4875)
E/AndroidRuntime(13215):    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4576)
E/AndroidRuntime(13215):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3780)
E/AndroidRuntime(13215):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2518)
E/AndroidRuntime(13215):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9389)
E/AndroidRuntime(13215):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1451)
E/AndroidRuntime(13215):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1459)
E/AndroidRuntime(13215):    at android.view.Choreographer.doCallbacks(Choreographer.java:1089)
E/AndroidRuntime(13215):    at android.view.Choreographer.doFrame(Choreographer.java:1003)
E/AndroidRuntime(13215):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1431)
E/AndroidRuntime(13215):    at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(13215):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13215):    at android.os.Looper.loopOnce(Looper.java:210)
E/AndroidRuntime(13215):    at android.os.Looper.loop(Looper.java:299)
E/AndroidRuntime(13215):    at android.os.HandlerThread.run(HandlerThread.java:67)

I only found some older questions talking about this error, and what they recommended was to put the offending image from drawable into drawable-xxhdpi folder. But in my android/app/src/main/res/drawable and android/app/src/main/res/drawable-v21 folder I only have a file called launch_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <!-- <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item> -->
</layer-list>

Also in the res folder I have values/styles.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
    <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             the Flutter engine draws its first frame -->
        <item name="android:windowBackground">@mipmap/splash</item>
    </style>
    <!-- Theme applied to the Android Window as soon as the process has started.
         This theme determines the color of the Android Window while your
         Flutter UI initializes, as well as behind your Flutter UI while its
         running.

         This Theme is only used starting with V2 of Flutter's Android embedding. -->
    <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

I am using different locations for my splashscreens, like res/mipmap-mdpi/splash.png up to xxxhdpi. Is also have a res/mipmap-anydpi-v26/ic-launcher.xml file:

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  <background android:drawable="@mipmap/ic_launcher_adaptive_back"/>
  <foreground android:drawable="@mipmap/ic_launcher_adaptive_fore"/>
</adaptive-icon>

Could that one be the issue?

My AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application
        android:label="todo4u"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:enableOnBackInvokedCallback="true">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:exported="true"
            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">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <!-- Deep Links -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
                <data
                android:scheme="https"
                android:host="tdapp-af2db.web.app" />
            </intent-filter>
            <!-- App Links -->
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with https://YOUR_HOST -->
                <data
                android:scheme="https"
                android:host="tdapp-af2db.web.app" />
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
</manifest>
0

There are 0 answers