jonbhanson / flutter_native_splash

Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.
https://pub.dev/packages/flutter_native_splash
MIT License
1.29k stars 202 forks source link

Android 12 #506

Closed paulobreim closed 1 year ago

paulobreim commented 1 year ago

Hi friends,

My app doesn't show splashscreen on Android 12. I have a galaxy S10E and I used the following configuration:

dependencies:
   flutter:
     sdk: flutter
   platform_device_id: ^1.0.1
   package_info_plus: ^1.3.0
   update_available: ^2.0.0
   url_launcher: ^6.1.8 
   webview_flutter: ^4.0.2 
   slide_digital_clock: ^1.0.2
   just_audio: ^0.9.31 
   connectivity_plus: ^3.0.2 
   google_mobile_ads: ^2.3.0 
   flutter_native_splash: ^2.2.17
   http: ^0.13.5

flutter_native_splash:
   color: "#3A4F62"
   image: assets/images/splash.png
   android: true
   ios: false
   android_gravity: fill
   android_12:
     color: "#3A4F62"
     image: assets/images/splash.png

The color #3A4F62 is displayed as the background and the default icon appears.

flutter pub run flutter_native_splash:create
[Android] Creating default splash images
[Android] Creating default android12splash images
[Android] Creating dark mode android12splash images
[Android] Updating launch background(s) with splash image path...
[Android] - android/app/src/main/res/drawable/launch_background.xml
[Android] - android/app/src/main/res/drawable-v21/launch_background.xml
[Android] Updating styles...
[Android] - android/app/src/main/res/values-v31/styles.xml
[Android] - android/app/src/main/res/values-night-v31/styles.xml
[Android] - android/app/src/main/res/values/styles.xml
Web folder not found, skipping web splash update...
╔════════════════════════════════════════════════════════════════════════════╗
║ WHAT IS NEW: ║
╠════════════════════════════════════════════════════════════════════════════╣
║ You can now keep the splash screen up while your app initializes! ║
║ No need for a secondary splash screen anymore. Just use the remove() ║
║ method to remove the splash screen after your initialization is complete. ║
║ Check the docs for more info. ║
╚════════════════════════════════════════════════════════════════════════════╝

✅ Native splash complete.
Now go finish building something awesome! 💪 You rock! 🤘🤩Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash

[pcb@pcb-asus aeroescuta]$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.10, on Manjaro Linux 5.15.82-1-MANJARO, locale pt_BR.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc5)
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.3)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

• No issues found!

photo_2023-01-25_21-55-54

======================== In a second test, I just comment the specifications for Android 12

flutter_native_splash:
   color: "#3A4F62"
   image: assets/images/splash.png
   android: true
   ios: false
   android_gravity: fill
   #android_12:
     #color: "#3A4F62"
     #image: assets/images/splash.png

and... may be I found a new bug:

flutter clean
Deleting build...                                                  430ms
Deleting .dart_tool...                                              10ms
Deleting Generated.xcconfig...                                       1ms
Deleting flutter_export_environment.sh...                            0ms
Deleting ephemeral...                                                0ms
Deleting ephemeral...                                                1ms
Deleting ephemeral...                                                0ms
Deleting .flutter-plugins-dependencies...                            0ms
Deleting .flutter-plugins...                                         0ms
[pcb@pcb-asus aeroescuta]$ flutter pub get
Running "flutter pub get" in aeroescuta...                          4,1s
[pcb@pcb-asus aeroescuta]$ flutter pub run flutter_native_splash:create
[Android] Creating default splash images
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Deleting android12splash.png
[Android] Updating launch background(s) with splash image path...
[Android]  - android/app/src/main/res/drawable/launch_background.xml
[Android]  - android/app/src/main/res/drawable-v21/launch_background.xml
[Android] Updating styles...
[Android]  - android/app/src/main/res/values/styles.xml
Web folder not found, skipping web splash update...
╔════════════════════════════════════════════════════════════════════════════╗
║                                 WHAT IS NEW:                               ║
╠════════════════════════════════════════════════════════════════════════════╣
║ You can now keep the splash screen up while your app initializes!          ║
║ No need for a secondary splash screen anymore. Just use the remove()       ║
║ method to remove the splash screen after your initialization is complete.  ║
║ Check the docs for more info.                                              ║
╚════════════════════════════════════════════════════════════════════════════╝

✅ Native splash complete.
Now go finish building something awesome! 💪 You rock! 🤘🤩
Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash

And when I compile I got this error

Launching lib/main.dart on SM G970F in debug mode...
Note: /home/pcb/development/flutter/.pub-cache/hosted/pub.dartlang.org/device_info-2.0.3/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > Android resource linking failed
     ERROR:/home/pcb/AndroidStudioProjects/aeroescuta/android/app/src/main/res/values-v31/styles.xml:4:5-10:13: AAPT: error: resource drawable/android12splash (aka aeroescuta.com.br:drawable/android12splash) not found.

     ERROR:/home/pcb/AndroidStudioProjects/aeroescuta/android/app/src/main/res/values-night-v31/styles.xml:4:5-10:13: AAPT: error: resource drawable/android12splash (aka aeroescuta.com.br:drawable/android12splash) not found.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 39s
Exception: Gradle task assembleDebug failed with exit code 1
Exited

Looking the values-v31/styles.xml and values-night-v31/styles.xml we have

<?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">
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
        <item name="android:windowSplashScreenBackground">#3A4F62</item>
        <item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</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>

========================

What am I doing wrong?

Thank you Paulo

jonbhanson commented 1 year ago

As noted in the Android 12 section of the readme,

PLEASE NOTE: There are a number of reports that non-Google launchers do not display the launch image correctly. If the launch image does not display correctly, please try the Google launcher to confirm that this package is working.

PLEASE NOTE: The splash screen does not appear when you launch the app from a notification. Apparently this is the intended behavior on Android 12: core-splashscreen Icon not shown when cold launched from notification.

I suspect the problem is with a Samsung launcher on Andrdoid 12. Try launching in an emulator so that you are using the Google launcher. Don't launch it by running it from Android studio, but actually open the launcher in Andriod and launch by tapping the app icon. If the splash is correct, you will know that the problem is with the Samsung launcher.

paulobreim commented 1 year ago

Thank you for your answer.

I'll try to do more tests. There is a problem that I think you should check: When I run flutter pub run flutter_native_splash:create everything works correctly, but if I run it the first time with android12 declarations, for example: android_12: color: "#3A4F62" image: assets/images/splash.png

but if I remove the Android12 declaration, when run flutter pub run flutter_native_splash:create again, it is not eliminating the line referring to Android 12, from the files android/app/src/main/res/values-v31/styles.xml and android/app/src/main/res/values-night-v31/styles.xml and when compiling the project the error.

tks paulo

wesleytoshio commented 1 year ago

same here using android 12

wesleytoshio commented 1 year ago

DEMO: ezgif-5-a2bcc97adc

ANDROID VERSION: image

FILE SETTINGS

flutter_native_splash:
  color: "#3A4F62"
  image: "assets/splash.png"
  android: true
  ios: false
  android_gravity: fill
  android_12:
    color: "#15B347"
    image: "assets/android12splash.png"
    icon_background_color: "#952727"

FLUTTER AND PACKAGE VERSION: Flutter (Channel stable, 3.3.10, on Microsoft Windows [versÆo 10.0.22000.1455], locale pt-BR) flutter_native_splash: ^2.2.17

paulobreim commented 1 year ago

Finally after spending hours searching, I found the solution.

I remembered that I had an older version of the app where the splashscreen worked without any problems. So I started comparing files by files, replacing them one by one, compiling and testing them directly on my Galaxy S10E.

I found a difference in the android/app/src/main/AndroidManifest.xml file, the worked version, has some lines, that does not exist in a new version. See below.


   <application
        android:label="aeroescuta"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="false">
        <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"
            android:exported="true">
            <!-- 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"
              />

          ** JUST ADD THESE LINES **
           <!-- 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"
              />

So I put that part and the splashscreen started to work.

I tested it on another app with the same problem and it worked too.

@wesleytoshio Can you test it?

@jonbhanson I don´t have a technical explanation about it.
jonbhanson commented 1 year ago

@paulobreim glad to hear you got it working.

paulobreim commented 1 year ago

@paulobreim glad to hear you got it working.

it is a bug's flutter or we will need to do it everytime?

jonbhanson commented 1 year ago

I don't know why adding that line back in made it work. According to Flutter's docs, that line should be removed in Android 12.

arno608rw commented 1 year ago

@paulobreim Thank, It work.

dai10512 commented 1 year ago

https://github.com/jonbhanson/flutter_native_splash/issues/506#issuecomment-1407761555 @wesleytoshio I had same bug. But now, the bug was solved by adding code in AndroidManifest.xml.

      <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" /> // こっちを追加
dai10512 commented 1 year ago

@paulobreim https://github.com/jonbhanson/flutter_native_splash/issues/506#issuecomment-1407780313

It was big hint. Great appreciate!

jonbhanson commented 1 year ago

@dai10512 @arno608rw @paulobreim do you have provideSplashScreen implemented in your FlutterActivity? In reading the Deprecated Splash Screen API Migration Guide, part of the instructions include removing provideSplashScreen() in addition to removing the SplashScreenDrawable from AndroidManifest.xml. I suspect your problem may have come from removing one but not the other.

robman70 commented 1 year ago

Finally after spending hours searching, I found the solution.

I remembered that I had an older version of the app where the splashscreen worked without any problems. So I started comparing files by files, replacing them one by one, compiling and testing them directly on my Galaxy S10E.

I found a difference in the android/app/src/main/AndroidManifest.xml file, the worked version, has some lines, that does not exist in a new version. See below.

   <application
        android:label="aeroescuta"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="false">
        <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"
            android:exported="true">
            <!-- 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"
              />

          ** JUST ADD THESE LINES **
           <!-- 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"
              />

So I put that part and the splashscreen started to work.

I tested it on another app with the same problem and it worked too.

@wesleytoshio Can you test it?

@jonbhanson I don´t have a technical explanation about it.

Same problem here but removing SplashScreenDrawable is part of the migration to Android 12...

https://docs.flutter.dev/development/platform-integration/android/splash-screen-migration

That solution is strange... it is also specified that it could cause some crashes.

Or am I missing something?

jonbhanson commented 1 year ago

That solution is strange... it is also specified that it could cause some crashes.

Do you mean this part?:

Delete the meta-data element, as Flutter no longer uses that, but it can cause a crash.

I understand this to mean that you should delete the meta-data element because leaving it can cause a crash.

Same problem here

Were you able to solve the problem by following the migration guide?

robman70 commented 1 year ago

That solution is strange... it is also specified that it could cause some crashes.

Do you mean this part?:

Delete the meta-data element, as Flutter no longer uses that, but it can cause a crash.

I understand this to mean that you should delete the meta-data element because leaving it can cause a crash.

Yes. And that's why that solution seems strange to me.

Same problem here

Were you able to solve the problem by following the migration guide?

Nope. My app was already correct, there is neither provideSplashScreen, nor SplashScreenDrawable but at first start after install, no Launch Image is showed.

robman70 commented 1 year ago

I did another test and it seems to me a problem related only to launching the application from Flutter (flutter run) and only on Android 12 devices.

In fact I tried to: 1 - Completely uninstall the app from your device 2 - Build the app in debug (flutter build apk --debug) 3 - Install the app on the device (flutter install --debug) 4 - Run the app directly in the device

The launch screen is always shown, even on first startup.

DaliaPinto23 commented 10 months ago

Finally after spending hours searching, I found the solution.

I remembered that I had an older version of the app where the splashscreen worked without any problems. So I started comparing files by files, replacing them one by one, compiling and testing them directly on my Galaxy S10E.

I found a difference in the android/app/src/main/AndroidManifest.xml file, the worked version, has some lines, that does not exist in a new version. See below.

   <application
        android:label="aeroescuta"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="false">
        <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"
            android:exported="true">
            <!-- 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"
              />

          ** JUST ADD THESE LINES **
           <!-- 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"
              />

So I put that part and the splashscreen started to work.

I tested it on another app with the same problem and it worked too.

@wesleytoshio Can you test it?

@jonbhanson I don´t have a technical explanation about it.

@paulobreim It works for me, thanks

AshrafZarkani commented 9 months ago

Finally after spending hours searching, I found the solution.

I remembered that I had an older version of the app where the splashscreen worked without any problems. So I started comparing files by files, replacing them one by one, compiling and testing them directly on my Galaxy S10E.

I found a difference in the android/app/src/main/AndroidManifest.xml file, the worked version, has some lines, that does not exist in a new version. See below.

   <application
        android:label="aeroescuta"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="false">
        <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"
            android:exported="true">
            <!-- 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"
              />

          ** JUST ADD THESE LINES **
           <!-- 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"
              />

So I put that part and the splashscreen started to work.

I tested it on another app with the same problem and it worked too.

@wesleytoshio Can you test it?

@jonbhanson I don´t have a technical explanation about it.

I have spent nearly 6 hours searching for a solution. Thank you !