Flutter 设置安卓启动页报错 java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bitmap.
设置安卓启动页报错
-
首先设置安卓启动页
-
在android/app/src/main/AndroidManifest.xml中添加这一行
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />
-
然后找到android/app/src/main/res/drawable/launch_background.xml
-
添加代码
<!-- You can insert your own image assets here -->
<item>
<!-- android:gravity="center" -->
<bitmap
android:src="@drawable/splash"/>
</item>
-
如果在这里不行就将代码放在同级的另一个drawable-v21文件夹中,然后将图片放在drawable文件夹中
-
结果运行之后发现报错图片太大,在网上压缩图片从2.9MB到400K都还是报错,最后在stackflow上找到解决办法
Move your image in the drawable to mipmap-xxhdpi.Your image is in bitmap format so you should put your image in mipmap folder,then it will work
-
将图片从drawable中移动到mipmap-xxxhdpi中
-
然后更改drawable或者drawable-21文件夹中launch_background.xml的代码为新的地址
<item>
<bitmap android:src="@mipmap/splash" />
</item>
- 就好啦