Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.49k stars 374 forks source link

Child pages are not rendered after exiting a nested initial page with the back gesture and launching from the Android launcher. #1947

Open kouroku-room opened 2 weeks ago

kouroku-room commented 2 weeks ago

I do not own an Android device, so I am using an Android emulator to check the operation. Sorry if others have not been able to reproduce this and the behavior is specific to my emulator.

Environment

Android Emulator version 34.2.13 Android Emulator hypervisor driver (installer) version 2.2.0

flutter doctor -v ```bash PS C:\projects\sampleForIssue> flutter doctor -v [√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22631.3447], locale ja-JP) • Flutter version 3.19.6 on channel stable at C:\src\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 54e66469a9 (13 days ago), 2024-04-17 13:08:03 -0700 • Engine revision c4cd48e186 • Dart version 3.3.4 • DevTools version 2.31.1 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3) • Android SDK at C:\Users\sugur\AppData\Local\Android\sdk • Platform android-34, build-tools 35.0.0-rc3 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.4) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.9.34714.143 • Windows 10 SDK version 10.0.22000.0 [√] Android Studio (version 2023.3) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160) [√] VS Code (version 1.88.1) • VS Code at C:\Users\sugur\AppData\Local\Programs\Microsoft VS Code • Flutter extension can be installed from: https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [√] Connected device (4 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 14 (API 34) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.3447] • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.91 • Edge (web) • edge • web-javascript • Microsoft Edge 124.0.2478.67 [√] Network resources • All expected network resources are available. • No issues found! ```

Example Code

Example Code pubspec.yaml: ```pubspec.yaml name: sample_for_issue description: "A new Flutter project." publish_to: 'none' version: 1.0.0+1 environment: sdk: '>=3.3.3 <4.0.0' dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.8 auto_route: 8.1.3 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^3.0.2 auto_route_generator: ^8.0.0 build_runner: ^2.4.9 flutter: uses-material-design: true ``` app_router.dart: ```app_router.dart import 'package:auto_route/auto_route.dart'; import 'main.dart'; part 'app_router.gr.dart'; @AutoRouterConfig(replaceInRouteName: 'Page,Route') class AppRouter extends _$AppRouter { @override List get routes => [ AutoRoute( page: ParentRoute.page, initial: true, children: [ AutoRoute(page: ChildRoute.page, initial: true), ], ), ]; } ``` main.dart: ```main.dart import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'app_router.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { MyApp({super.key}); final _appRouter = AppRouter(); @override Widget build(BuildContext context) { return MaterialApp.router( theme: ThemeData( useMaterial3: true, ), routerConfig: _appRouter.config(), ); } } @RoutePage() class ParentPage extends StatelessWidget { const ParentPage({super.key}); @override Widget build(BuildContext context) { return Stack( fit: StackFit.expand, children: [ Container( color: Theme.of(context).colorScheme.secondaryContainer, ), const AutoRouter(), ], ); } } @RoutePage() class ChildPage extends StatelessWidget { const ChildPage({super.key}); @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, appBar: AppBar( title: const Text('Child'), ), body: const Center( child: Column( children: [ Text( 'Child', ), ], ), ), ); } } ```

Procedure

  1. Install the app and launch it (either by using the Run button in Android Studio or by installing the built Release APK, in both cases the problem occurred). ChildPage is displayed at this time.

  2. Perform the back process (whether by back key or gesture by swiping, the bug occurred in both cases).

  3. Tap the app in the launcher.

-> ParentPage is rendered, but ChildPage is not.

https://github.com/Milad-Akarie/auto_route_library/assets/57855128/c01a8e5c-960e-481d-b1c7-f7e2b2b65c64

Log(~ parts is my added) ``` Launching lib\main.dart on sdk gphone64 x86 64 in debug mode... Running Gradle task 'assembleDebug'... √ Built build\app\outputs\flutter-apk\app-debug.apk. Installing build\app\outputs\flutter-apk\app-debug.apk... Debug service listening on ws://127.0.0.1:59902/WsRGL123o4A=/ws Syncing files to device sdk gphone64 x86 64... ~ back pressed ~ D/EGL_emulation(18126): app_time_stats: avg=12504.26ms min=12.23ms max=24996.28ms count=2 W/WindowOnBackDispatcher(18126): sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda17@2140e8e W/ample_for_issue(18126): Cleared Reference was only reachable from finalizer (only reported once) ~ app icon tapped on launcher ~ W/OpenGLRenderer(18126): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... W/OpenGLRenderer(18126): Failed to initialize 101010-2 format, error = EGL_SUCCESS E/OpenGLRenderer(18126): Unable to match the desired swap behavior. E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 E/emuglGLESv2_enc(18126): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502 ```

This may be related to a bug in the emulator, as the following logs are displayed.

https://github.com/flutter/flutter/issues/146890

E/emuglGLESv2_enc(17550): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2183 GL error 0x502

According to this Issue (https://github.com/flutter/flutter/issues/146890), Android Emulator version 35 is the cause of the bug and that version has already been removed. However, I am encountering this bug (#1947) with Android Emulator version 34.2.13.

Is this a bug that other users are also experiencing with the emulator? And is it a bug that does not occur on the actual device?

d029940 commented 2 weeks ago

I have a similar problem with the emulator. From AndroidStudio (or VSCode) launched the app and it shows nicely. Then I close the app and restart it again. => Black screen and error message: E/emuglGLESv2_enc( 4107): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502

MG-LSJ commented 2 weeks ago

This only started to happen when I updated Android Studio

AbdelrahmanEsam commented 2 weeks ago

@MG-LSJ in android studio Iguana that doesn't happen the first time you install your app or if your cache cleared ... otherwise this will happen .

d029940 commented 2 weeks ago

I completely uninstalled AndroidStudio on Windows. Deleted %appdata%/local/Android and .android in the home folder and reinstalled again. Now it works. So, probably the update caused the error. Likely, clearing the cache would have solved the problem.

So, thank you.

AbdelrahmanEsam commented 2 weeks ago

@d029940 with me it doesn't ... you need to clear cache of the app everytime .

d029940 commented 2 weeks ago

I tried several emulators. I have still no solution, but may be a hint. If I created an emulator from the predefined list, and I choose API 30 or less. A system image x86 will be taken. This works. If I take an API greater than 30, a system image x86_64 is applied. Now I have the same problem. Either the app must be uninstalled or the cache cleared.

Then I created a new emulator and used "New hardware profile". (Not one from the predefined list). I chose an API greater than 30. And it will work. Regardless whether you chose software or hardware for graphics mode.

So, I think choosing an emulator from the predefined list and selecting an API greater than 30 (i.e. x86_64 image), you will run into an error. Maybe the predefined hardware profiles don't match.

Additionally viewing details of the emulators with regards to gpu, I am getting the following info:

Predefined Pixel 8 (API 34): hw.gpu.enabled = yes, hw.gpu.mode = auto => error Device defined by myself (API 34): hw.gpu.enabled = yes, hw.gpu.mode = host => works Predefined Pixel 8 (API 30): hw.gpu.enabled = yes, hw.gpu.mode = auto => works

I am on Windows 11, latest AndroidStudio / SDK. It doesn't matter if the hypervisor is from Microsoft (Windows Pro version) or if the hypervisor is taken from the SDK. Same results.

Very confusing. I would advice that you try to create an emulator yourself - and not using one of the predefined ones.

kouroku-room commented 1 week ago

Thanks for confirming this problem.

~~I've reported it on Google's Issue Tracker as similar issues seem to occur to others. https://issuetracker.google.com/issues/338667188~~

-> Google's Issue Tracker was not the appropriate place to report it, so I reported it to the Flutter team. https://github.com/flutter/flutter/issues/148347

kouroku-room commented 1 week ago

I tried several emulators. I have still no solution, but may be a hint. If I created an emulator from the predefined list, and I choose API 30 or less. A system image x86 will be taken. This works. If I take an API greater than 30, a system image x86_64 is applied. Now I have the same problem. Either the app must be uninstalled or the cache cleared.

Then I created a new emulator and used "New hardware profile". (Not one from the predefined list). I chose an API greater than 30. And it will work. Regardless whether you chose software or hardware for graphics mode.

So, I think choosing an emulator from the predefined list and selecting an API greater than 30 (i.e. x86_64 image), you will run into an error. Maybe the predefined hardware profiles don't match.

Additionally viewing details of the emulators with regards to gpu, I am getting the following info:

Predefined Pixel 8 (API 34): hw.gpu.enabled = yes, hw.gpu.mode = auto => error Device defined by myself (API 34): hw.gpu.enabled = yes, hw.gpu.mode = host => works Predefined Pixel 8 (API 30): hw.gpu.enabled = yes, hw.gpu.mode = auto => works

I am on Windows 11, latest AndroidStudio / SDK. It doesn't matter if the hypervisor is from Microsoft (Windows Pro version) or if the hypervisor is taken from the SDK. Same results.

Very confusing. I would advice that you try to create an emulator yourself - and not using one of the predefined ones.

I tried this opinion, but it seems to cause an error in my environment...

[Create Virtual Device] -> [New Harware Profile] -> [Create(All Default settings)] ->this Hardware Profile + API 34 ->error (same behavior as issue video)

However, I was able to do it in my environment without any problems with API 30 too! Predefined Pixel 8 (API 30) => works

The above information was tested without reinstalling Android Studio.


Added

I did a clean install of Android Studio, but the behavior did not change. Relation file ("C:\Users\username.android" & "C:\Users\username\AppData\Roaming\Google" & "C:\Users\username\AppData\Local\Android" ) deleted.