Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kouroku-room opened this issue May 6, 2024 · 18 comments
Assignees
Labels
P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@kouroku-room
Copy link

At first I thought it was a bug on the library side (https://pub.dev/packages/auto_route), but I am reporting it here because it probably only occurs in the Android Emulator.

Please check Issue (Milad-Akarie/auto_route_library#1947) for the results of defect verification by several other people.

I also reported it to Google's Issue Tracker (https://issuetracker.google.com/issues/338667188), but they commented that I should submit it here.

Environment

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

flutter doctor -v
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:

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:

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<AutoRoute> get routes => [
        AutoRoute(
          page: ParentRoute.page,
          initial: true,
          children: [
            AutoRoute(page: ChildRoute.page, initial: true),
          ],
        ),
      ];
}

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.

issue.mp4
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.

#146890

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

According to this Issue (#146890), Android Emulator version 35 is the cause of the bug and that version has already been removed.
However, I am encountering this bug with Android Emulator version 34.2.13.

@plasenca
Copy link

plasenca commented May 9, 2024

In my case, i had to downgrade to this version of dart sdk.

environment:
  sdk: ">=3.1.3 <4.0.0"

I was using this one.

environment:
  sdk: ">=3.2.0 <4.0.0"

@jwren jwren transferred this issue from flutter/flutter-intellij May 14, 2024
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 15, 2024
@darshankawar
Copy link
Member

@kouroku-room Thanks for the report. Does the same occur in any physical android device or is it specific to emulators only ?
Also, since auto_route is a third party package, is it possible for you to remove that code implementation and check if only using framework code, you are able to replicate the behavior still ? If so, please provide us updated code sample without third party implementation.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 15, 2024
@kouroku-room
Copy link
Author

@darshankawar
Today I purchased a physical Android device (AQUOS wish3, Android 14 (AQUOS UX Version: 14.0.000)) and tested its operation.
As a result, this issue did not occur.
Therefore, the issue seems to occur only in Android emulators.

I have never implemented screen transitions, etc. using anything other than the auto_route library, so it is difficult to provide code. I'm so Sorry.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 15, 2024
@darshankawar
Copy link
Member

I have never implemented screen transitions, etc. using anything other than the auto_route library, so it is difficult to provide code. I'm so Sorry.

Can you try using https://docs.flutter.dev/ui/navigation and see if you are able to replicate this ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 16, 2024
@kouroku-room
Copy link
Author

@darshankawar
I was able to reproduce this without auto_route!

flutter doctor -v
PS C:\projects\sampleForIssue> flutter doctor -v
[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Version 10.0.22631.3593], locale ja-JP)
    • Flutter version 3.22.0 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5dcb86f68f (7 days ago), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\sugur\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • 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.89.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 (5 available)
    • SH M25 (mobile)              • adb-SX3LHMB420105423-I4myh9._adb-tls-connect._tcp • android-arm64  • Android 14 (API 34)
    • 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.3593]
    • Chrome (web)                 • chrome                                            • web-javascript • Google Chrome 124.0.6367.158
    • Edge (web)                   • edge                                              • web-javascript • Microsoft Edge 124.0.2478.105
    ! Device SX3LHMB420105423 is offline.

[√] Network resources
    • All expected network resources are available.

• No issues found!

Example Code

Example Code

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

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.2

flutter:
  uses-material-design: true

main.dart:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        useMaterial3: true,
      ),
      routes: {
        '/': (_) => const ParentPage(),
      },
    );
  }
}

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,
        ),
        Navigator(
          pages: const [
            MaterialPage(
              key: ValueKey('ChildPage'),
              child: ChildPage(),
            ),
          ],
          onPopPage: (route, result) {
            return true;
          },
        ),
      ],
    );
  }
}

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',
            ),
          ],
        ),
      ),
    );
  }
}

This code also caused issue with the Android emulator, and not caused issue with the physical Android device.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 16, 2024
@darshankawar
Copy link
Member

@kouroku-room
I tried the same using latest stable but was unable to replicate the reported behavior. See video for details:

148347.mov

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@kouroku-room
Copy link
Author

kouroku-room commented May 17, 2024

@darshankawar
Is the same true for API 34?

I tried with Android 14 (API 34) (emulator).

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@darshankawar
Copy link
Member

I tried with Android 14 (API 34) (emulator).

If it is specific to Android 14, then you might be hitting #146499 which you can check and confirm.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@kouroku-room
Copy link
Author

kouroku-room commented May 17, 2024

I also tried it with Pixel XL API 33 Emulator and reproduce this issue...

sample_for_issue.main.dart.sample_for_issue.2024-05-17.19-51-57.mp4

Therefore, #146499 may not be relevant.

I'll share my sample project (rev. 26946eca is the sample without auto_route) where the problem occurs, just in case.
https://github.com/kouroku-room/sample_for_issue/tree/26946eca4c0b7304526ae4dc74e7f18baae793b8

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@mr-pant
Copy link

mr-pant commented May 17, 2024

@darshankawar I was facing #146499 before on my Samsung Galaxy A53 5G device (Android 14), and after latest Flutter 3.22.0, that issue is resolved but I still see the issue mentioned here for the platform view. Please check comment #146499 (comment)

@kouroku-room, after you see this issue, if you open the app from recent apps launcher, does the child page start showing up again?

@kouroku-room
Copy link
Author

kouroku-room commented May 17, 2024

@kouroku-room, after you see this issue, if you open the app from recent apps launcher, does the child page start showing up again?

@mr-pant No. Once this issue occurs, it seems to start in the state in which it occurs, even if opened from the recent apps launcher.
([Home button -> Overview button -> tap my sample app] and [Home button -> tap settings app -> Overview button -> tap my sample app])

I also tried Developer option -> Don't keep activities but same reproduce.

Once this issue occurs, "Uninstall" or "Deleting app data (Settings app -> Storage & cache => Clear storage)" seems to make it appear correctly.
I could not find any other way to get it to render correctly other than that way.

I confirmed with "Pixel 8 API 33", "Pixel 8 API 34" and "Pixel XL API 33" in Android emulator and same reproduce.

@darshankawar
Copy link
Member

I confirmed with "Pixel 8 API 33", "Pixel 8 API 34" and "Pixel XL API 33" in Android emulator and same reproduce.

I tried again on Pixel XL api 33 but wasn't able to replicate the reported error and also per my earlier verification.
Based on the report, I will keep the issue open for team's input / attention.

@darshankawar darshankawar added platform-android Android applications specifically team-android Owned by Android platform team and removed in triage Presently being triaged by the triage team labels May 20, 2024
@kouroku-room
Copy link
Author

I understand. Thanks for team's cooperation.

If someone have the same problem and find this Issue, I would be glad if you could report your environment (flutter doctor -v, Android Studio Version, Emulator Version, Emulator Device Info, etc.) here.

@eduardofcr
Copy link

eduardofcr commented May 20, 2024

same problem

On a real device the problem does not occur at all.
but with the Android emulator, the problem appears after the first run (on the first run it works fine)
in the IOS emulator it always works well

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.0, on Pop!_OS 22.04 LTS 6.8.0-76060800daily20240311-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.89.1)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

@dschniedertuens-tc
Copy link

I am experiencing the same problem with Android emulator version 34.2.13. Switching back to 34.1.20 resolves the problem. Tested with Android API version 34 and 32.

It's reproducible with the example from #148347 (comment)

Please let me know if I can give any further detail.

flutter doctor -v

[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Version 10.0.22631.3593], locale de-DE) • Flutter version 3.22.0 on channel stable at C:\ProgramData\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5dcb86f (11 days ago), 2024-05-09 07:39:20 -0500 • Engine revision f6344b75dc • Dart version 3.4.0 • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:\ProgramData\Android\Sdk
• Platform android-34, build-tools 34.0.0
• 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_EXECUTABLE = C:\Projekte Zusatzdaten\Android\google-chrome-unsafe.bat

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.7)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.9.34902.65
• Windows 10 SDK version 10.0.20348.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
• android-studio-dir = C:\Program Files\Android\Android Studio
• Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)

[√] VS Code, 64-bit edition (version 1.89.1)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.88.0

[√] 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.3593]
• Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.208
• Edge (web) • edge • web-javascript • Microsoft Edge 122.0.2365.59

[√] Network resources
• All expected network resources are available.

• No issues found!

@eduardofcr
Copy link

thank you very much!
The emulator downgrade fix the problem :)

@kouroku-room
Copy link
Author

kouroku-room commented May 21, 2024

I am experiencing the same problem with Android emulator version 34.2.13. Switching back to 34.1.20 resolves the problem.

I tried to downgrade to Android Emulator 34.1.20. When I did so, this problem did not occur!

Reference: How to manually install a select version of emulator https://developer.android.com/studio/emulator_archive

Note: Android emulator versions 34.2.13 (Stable) and latest 35.1.9 (Canary) occur this problem.
Therefore, it is likely that this problem was planted in the fix between 34.1.20 and 34.2.13. And which has not yet been fixed.

@gmackall gmackall self-assigned this May 23, 2024
@gmackall gmackall added P2 Important issues not at the top of the work list triaged-android Triaged by Android platform team labels May 23, 2024
@gmackall
Copy link
Member

Assigning to myself to try to reproduce for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests

7 participants