I was recently trying to add a splash screen to my android app that I am trying to develop. But no matter what changes I make changes are not getting reflected. I am new to flutter to I am including a lot of code. Here is the code -
values>colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">#FFCC00</color>
</resources>
drawable>>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="#color/background_color" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="#drawable/welcome" />
</item> -->
</layer-list>
I am using flutter channel 'master' as Android Studio 4.1.2 is not supported in channel 'stable'
Please inform me if any other code is required. Thanks in advance.
I tried a lot of stuff. Wasted nearly 14 hours, to realize that Android Studio 4.1.2, has some sort of problem with flutter doctor as of 12/2/2021. So I switched back to Android Studio 4.0 and re-installed the flutter SDK. This solved the problem for me. As far as, I am aware of the issue, it was due to different unsupported versions of Android Studio and Flutter. Maybe in the future, smart guys at google sort this out :)
Just want to drop this here for those who may have this issue with React Native. What solved it for me was slightly renaming the splash screen file inside my assets folder. It was splash.png, after I made changes to it and overrode the file, the old splash screen kept showing.
Reloading, restarting the server, clearing cache, none solved it.
When I finally renamed the file to splashscreen.png and reload. Viola!
Related
I had implemented a native splash screen in my current project and everything was working correctly since I upgraded to v2.5.0 and I am starting to get this deprecation warning on my console:
A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
I have checked out the given link (which is not that clear btw) and tells me to remove the o.flutter.embedding.android.SplashScreenDrawable API as flutter now automatically displays the splash.
But after running my app without the code no splash screen appears moreover it takes a while to start the app - probably initializing the app without the splash or something.
Am I doing this right or is it an issue with the framework itself?
It is caused by having the following code in your AndroidManifest.xml, which was included by default in previous versions of Flutter:
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
The solution is to remove the above code.
Source
Follow this youtube tutorial on how to correctly Create Splash Screen in Flutter App the Right Way in 2021. Ensure to create the launch_background.xml file in both drawable and drawable-v21 folders inside the android/app/src/main/res folder.
Create Splash Screen in Flutter App the Right Way in 2021
If you are using Flutter 2.5, remove the following line in your AndroidManifest.xml file since Flutter 2.5 has no need for it anymore as mentioned here --> android splash migration
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"/>
Remove the below lines from your AndroidManifest.xml file. In newer versions it's no longer used
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme" />
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background" />
Here is one solution that worked in my case.
You have a "drawable" and "drawable-v21" folders on the path "android/app/src/main/res/" and you must open the "launch_background.xml" in "drawable-v21" folder, paste and a little bit refactor my code to provide your image or/and color:
<?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/your_color" />
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="center"
android:src="#drawable/your_image" />
</item>
</layer-list>
P.S. The image should be in "drawable" folder, not "drawable-v21". You can try, but in my case that didnt work and throw the error.
P.S.2 I didn't change the "AndroidManifest.xml", "styles.xml" and other files.
I have created a flutter application that works well on a physical phone but when I try it out on an emulator the application stops unfortunately. Error produced java.lang.RuntimeException: Unable to start activity ComponentInfo{big.xxxx.xxxxx/xxx.xxxxx.xxxxx.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/launch_background.xml from drawable resource ID #0x7f040019
I have checked and the launch_background.xml is present. Here is the content
<?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:colorBackground" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="#mipmap/launch_image" />
</item> -->
</layer-list>
Looks like you have deleted your launch_background.xml this is the first screen that is execute in your Android when you are using Flutter. Check in the path /android/app/src/main/drawable if you have the launch_background.xml.
If you don't you must added in your project.
After asking around I was able to solve the problem by removing the instances where I call the drawable file.
This was mainly in my styles.xml file and Manifest.xml file respectively.
<item name="android:windowBackground">#drawable/launch_background</item>
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="#drawable/launch_background" />
Had an opportunity of asking another person who had solved this problem differently and this is what he had to say.
The underlying cause
The underlying cause seems to be that the expects a bitmap but it didn't get one. Even though #mipmap/ic_launcher points to some PNGs (see e.g. res/mipmap-hdpi), on API >= 26, it would point to this XML which Android did not seem to like very much.
So in my case, referencing the #drawable (which is always a PNG == a nice bitmap) rather than the #mipmap (which may be an adaptive-icon == a weird bitmap? if a bitmap at all?) fixed it.
In other words: don't use an as the android:src of a .
If I'd to this today I would try if a vector drawable (just import an SVG in Android Studio to get the vector XML) works as well (as opposed to having to use a PNG).
Hope that helps (or at least explains this change of mine).
Do double check that you have the same issue - Resources$NotFoundException may be thrown for many different reasons, e.g. the ressource being in the drawable-v26 folder and thus ignored when running on e.g. API 24. Sometimes the gradle build log shows some warning saying that an XML failed to compile (but the build still succeeds and then things blow up at runtime).
Best search the internet for other causes and fixes for Resources$NotFoundException if it's not the same issue.
Just comment this out in android\app\src\main\AndroidManifest.xml
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"/>
I've got a problem with my flutter app when I want to resume my app on android. So I tested the example flutter app that gets generated, but the problem also exists there. I modified only the launch_background.xml file to change the background color to black and put the launcher icon to the splash screen.
The problem is that when I resume the app after I paused it, the splash screen is visible for a short period of time. The gif below shows the problem.
Does anyone know a solution for this or do I have to deal with that?
Thanks in advance
--EDIT--
Changes to the styles.xml in Android
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
</resources>
Try using flutter_native_splash. I use it in my all projects and it works flawlessly. Their doc says :
Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.
Make sure to run the package with below line after you make all the changes :
flutter pub pub run flutter_native_splash:create
EDIT AT THE END
I was trying to implement a SplashScreen following this guideline. So I'm setting a drawable with a layer-list and using an icon, but the icon is too big so I make a new file that's smaller. The result never showed up in my app: the first drawable I made is always showing up, never updating.
I renamed the picture file, the drawable
I renamed the style that's
used in the manifest
I cleaned the project
I rebuilt the project
I
synchroinized
I used the Invalidate cache/restart option
I updated
Android Studio
I moved my project folder, created a new one and
copy-pasted only the java and xml files because I thougt then the
cache files would be deleted
Nada, the old drawable is always showing when I deploy the apk on my phone.
What is this, whichcraft? What am I missing? Where do I find the cache? I looked for a bin folder, I read on some forums I should delete it but it's not in my workspace.
I'm posting my code below:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lu.intech.mcfc">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".activity.InitActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.LoginActivity" />
</application>
</manifest>
styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
</resources>
splash_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorPrimary"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/logo_wega_100x31"/>
</item>
</layer-list>
EDIT
I did try my app on another phone and it worked as intended straight away. So I'm guessing the problem lies on the phone. Even if I uninstalled the app everytime I tested again, the old drawable was shown. What more than uninstalling the app can I do to clean the cache on the phone?
I face the same problem but I guess it relates to Android Version.
I tested in a Samsung phone (Android 4.4.4) and windowBackground is updated immediately, but in a Sony phone (Android 7.0) it's not working. Seems like Android is trying to be "smarter" by saving some states of applications.
I did try all solutions that you tried, plus: via Application Manager -> Clear Cache, Clear Data. And... it's still not working.
Only one thing make it work: restart the device and then rebuild.
Yep, I'm not sure if user can face that problem when update our apps via Play Store. It's not convenience but it's only working solution that I found.
you need to clean out the system caches:
On the main menu, choose File | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart IntelliJ IDEA or both.
Application uninstall on your phone
Run project again.
First, try to clean you app then rebuild and relaunch it.
If not working, try to clean, uninstall on your phone, rebuild, then launch it again. Sometime when launching without cleaning some strange bugs appears.
Cf. another similar problem I had: Android status bar hide/change color in splash screen
It's not the first time I have a cache problem with that kind of screen, it must be the particular condition of having no layout and a drawable as a background. I tried invalidating the cache in Android Studio, I cleaned and rebuilt the project, I uninstalled the app on the phone but nothing works. So if you are in this cofiguration, just try to run your app on another phone if you can, just to check that your solution isn't already working, just not updating on your device.
I am trying to specify an menu icon for an Action Bar. I'm using Android Studio 1.2. My XML code follows:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/menu_connect"
android:icon="#drawable/ic_settings_bluetooth_white_24dp.png"
android:title="#string/menu_connect"
app:showAsAction="always"
/>
<item
android:id="#+id/menu_settings"
android:title="#string/menu_settings"
app:showAsAction="never"
/>
</menu>
The compiler complains about anything that I put after "android:icon=". Depending on what I've changed last, I get: "No resource found that matches the given name" or "String types not allowed" (among other errors).
I've tried suggestions from several posts. I cleared the Intellij cache and rebuilt everything and nothing changed. One post suggested that perhaps android:icon wasn't supported in earlier API versions so I set minSdkVersion to 23 (my current SDK version) in my module build script. I re-sync'd and again nothing changed.
I had some trouble figuring out how to set up the drawable directories for multiple resolution bitmaps. (Why doesn't Android Studio just create them when creating a new project?) I now have them (drawable-hdpi etc.) set up as siblings to the drawable directory. I think that's right. At least they appear to be correct in the Android directory view. Yeah, I'm a newbie.
Is there anything else that I can try?
Replace:
android:icon="#drawable/ic_settings_bluetooth_white_24dp.png"
with:
android:icon="#drawable/ic_settings_bluetooth_white_24dp"
You do not use file extensions when referring to resources from anywhere inside of Android.