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.
Related
I am seeing a weird issue with a new app that I am starting. I am utilizing the new Android 12 splash screen API to create my splash screen and I followed the guide provided by Google to do so. I included core-splashscreen in my project to provide compatibility with older versions of Android OS. When I run the app, I see the splash screen as expected on older OS versions like API 30, but when I run it on API 31, the splash screen icon that I provide is not displayed. The background color that I specify is displayed, but the icon is not there at all. I have tried this with a drawable asset as well as a mipmap and nothing is working. I am stumped as every tutorial I find shows the same steps I have followed and screenshots of their working splash screens, but I am not having any luck.
For context here is my splash screen style definition for v31:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">#color/orange_7A</item>
<item name="android:windowSplashScreenAnimatedIcon">#drawable/splash_foreground</item>
<item name="postSplashScreenTheme">#style/Theme.App</item>
</style>
I have an identical style for all other OS versions except I'm using "windowSplashScreenAnimatedIcon" instead of "android:windowSplashScreenAnimatedIcon". I have tried v31 with and without the "android:" in front of the item names and neither work. Here is my MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
MyVeevaTheme {
Login()
}
}
}
I am also setting the "android:theme" property to my splash style in my AndroidManifest.xml. I know the splash style is being applied because it honors the background color, but it is not showing the icon for some reason even though the icon shows fine for older OS versions. Thanks in advance for any help you can give.
TL;DR kill the app and run from the launcher, icon does not show up when run from Android Studio.
Adding my comment here as an answer for better visibility.
I did figure out how to get it to show. I was following this tutorial to set up a base project to recreate the issue and I noticed the note the author put right near the bottom that mentions that just running the app doesn't show the full splash screen. You have to kill it and open the app from the launcher. Once I did that, I was able to see my splash screen. Annoying, but at least I have a way to test it now. I did go ahead and log a bug report for this as well, but I have a work around for now. Thanks for everyone's answers/comments!
folks as per the document installSplashScreen() should have been called prior to super.onCreate()
When you use the AndroidX SplashScreen Library, like you are doing (Theme.SplashScreen) you need to use the windowSplashScreen* attributes without the android: prefix.
The android: prefix is used to call the platform attributes, but in this case you are using the library and not the platform, so no need for the prefix:
res/values/themes.xml:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/orange_7A</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/splash_foreground</item>
<item name="postSplashScreenTheme">#style/Theme.App</item>
</style>
For some reason when the app is launched through android studio it doesn't show the icon. Kill the app and launch app from the menu. Then the icon will appear.
This is true if you are not using Splash API: https://developer.android.com/develop/ui/views/launch/splash-screen/migrate
Icons are also not shown when navigating from the deeplink.
And It looks like its more then only not showing the icon. It also stops calling code for setOnExitAnimation lambda.
installSplashScreen().apply {
setOnAnimationListener { viewProvider ->
viewProvider.iconView
.animate()
.setDuration(500L)
.alpha(0f)
.withEndAnimation {
viewProvider.remove()
someActionCall()
}
.start()
}
If you relied upon this code to be always called it is not.
See mention in issue tracker: https://issuetracker.google.com/issues/207095799
The following instructions helped me, you may try this one. A few things need to keep in mind while working with the new splash screen API.
Keep updated on the latest library version. Follow this link (https://developer.android.com/jetpack/androidx/releases/core).
Put installSplashScreen() before setContentView()
Make a proper theme for the splash screen. You may try the following one.
Put this into your styles.xml or themes.xml folder and use it with your activity as the theme.
<!-- Splash Screen Theme. -->
<style name="Theme.AppSplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/white</item>
<item name="windowSplashScreenAnimatedIcon">#mipmap/ic_launcher_round</item>
<item name="windowSplashScreenAnimationDuration">1000</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
Make sure you set the theme to the MainActivity as well. For me that was the cause for the splash screen to now show. So you have to set the theme in both the application and the MainActivity
In addition to the other explanations above, I had the same issue but I realized that in my Manifest file I was setting the Splashscreen theme on my MainActivity which is correct, but my MainActivity was not having the main/launcher intent-filter which tells the android OS that this is the starting activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
So in your manifest, check that you are actually setting the Splashscreen theme on the Starting activity that is having the main/launcher intent-filter, and leave the Application tag to have your application theme and not the Splashscreen theme, to avoid having your app misbehave on other activities due to the theme because I experienced that too (This is especially for those migrating to the new splash screen).
Thank you, I hope someone finds this helpful
I had the same problem on my phone running Android 12. None of the above suggestions worked, (moving installSpashScreen() above super.onCreate etc...)
What fixed it for me was adding the android:theme attribute in the manifest to the Launching <activity> Tag, Not the <application> Tag, which is contrary to the documentation :
In the manifest, replace the theme of the starting activity to the theme you created in the previous step.
<manifest>
<application android:theme="#style/Theme.App.Starting">
<!-- or -->
<activity android:theme="#style/Theme.App.Starting">
Note, you still have to kill the activity and launch it from the launcher for this to work :(
In my case, the problem with the lack of a splash screen was the installation of the default activity theme:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name=".App"
android:theme="#style/Theme.Tracker.StartSplashScreen"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
tools:targetApi="tiramisu">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="#style/Theme.Tracker"> <-------
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I deleted android:theme="#style/Theme.Tracker" line, it started working.
I have a flutter app in which I have generated app icons for under the android folder of the project with the image asset tool that comes with android studio. On certain versions of android however neither this icon or flutter's default icon displays which seems to tell me this isn't just an issue with the icons I've provided, I instead get the default green android as such:
The screenshots above have come from an android 5 emulator (albeit quite old now its still technically supported by flutter so I wanted to test this) and I get the same problems on a physical device running android 7, but the icon seems to appear fine on any versions above. Something else I have noticed is that no app name appears in the multitasking menu but I'm not sure if that is a completely unrelated issue.
If anyone could help me that would be great, as I can't figure out what other icons I need to place in the project as I thought I'd covered all options. Thanks.
Edit- This is the android manifest for my app:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.letalis.testapp">
<application
android:label="Test App"
android:icon="#mipmap/ic_launcher">
<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">
<!-- 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"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</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>
</manifest>
Res folder:
Follow these Steps to Change/Customize Launcher Logo in Android Studio,
*Expand the project root folder in the Project View
*Right Click on the app folder
*In the Context Menu go to New->Image Asset
*In the pop up that appears select the the new logo you would like to have(image/clip art/text).
*If you were selecting the image radio button (as is the default choice), if you clicked on the 3-buttons to show the path tree to locate your .png image file, most probably you might not be seeing it, so drag it from the Windows Explorer (if Windows) and drop it in the tree, and it will appear and ready for being selected.
**Don't forget to set new icon's location in manifest: replace drawable to minimap in android:icon –
..........Mipmap Solution:
As you can see this Snapshot, I set Mipmap for every version, you can follow this also,
You have to create an XML file for anydpi-v26
`<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#color/ic_launcher_background"/>
<foreground android:drawable="#mipmap/ic_launcher_foreground"/>
</adaptive-icon>`
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!
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"/>
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.