Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Release] Page Restoration Restore Freezes and throws Dart Error: Class not found in library ''. #118565

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

Closed
nandaprasetio97 opened this issue Jan 16, 2023 · 3 comments · Fixed by #118738
Assignees
Labels
a: release Challenges faced when attempting to productionize an app a: state restoration RestorationManager and related APIs c: crash Stack traces logged to the console dependency: dart Dart team may need to help us found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: fixed Issue is closed as already fixed in a newer version

Comments

@nandaprasetio97
Copy link

nandaprasetio97 commented Jan 16, 2023

I have tried the sample given on this page regarding page restoration. When the application is running in debug mode (in app-debug.apk), the page restoration recovery is running. However, when the application is running in release (production) mode (in app-release.apk), the page restoration recovery freezes when switching from the application task via the multitask tray.

Steps to Reproduce

  1. Run flutter create --sample=widgets.RestorableRouteFuture.1 mysample for creating project based on this sample.
  2. Turn on developer mode and in these settings turn on "Don't keep activities".
  3. Run (through debug and release mode) this sample through phone/emulator.
  4. Create some in-memory state in the app on the phone, e.g. by navigating to a different screen.
  5. Background this sample app, then return to it.

Result

In Debug Mode

Expected results: Success restore its state.
Actual results: Success restore its state.

Video demonstration source: Here

In Release Mode

Expected results: Success restore its state.
Actual results: The restoration process suddenly freezes (it's been 10 seconds and it's still freezing).

Video demonstration source: Here

APK Source

APK Debug (app-debug.apk): Here
APK Release (app-release.apk): Here

Log

Using flutter doctor -v

Result:

[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.19045.2364], locale en-ID)
    • Flutter version 3.3.10 on channel stable at C:\flutter-3.3.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\android\Sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.2)
    • 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 11.0.12+7-b1504.28-7817840)

[√] Connected device (4 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.2364]
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 109.0.5414.74
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 108.0.1462.54

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Jan 17, 2023
@danagbemava-nc danagbemava-nc changed the title Page Restoration Restore Freezes While In Production Mode (app-release.apk) [Release] Page Restoration Restore Freezes and throws Dart Error: Class not found in library ''. Jan 17, 2023
@danagbemava-nc
Copy link
Member

danagbemava-nc commented Jan 17, 2023

I can reproduce the issue on both android and iOS using the RestorableRouteFuture sample code which can be generated by running flutter create --sample=widgets.RestorableRouteFuture.1 mysample.

Steps to reproduce

  • Generate the code sample using the command above or run the code sample below

Android

  • Turn on "Don't keep activities"
  • Run the code sample on an Android device using flutter run --release
  • Tap on the "open counter" button and click on the FAB on the next page to set some values in the counter
  • Background the Flutter app, then return to it.
  • You should see a blank screen
  • You should notice some errors in the logs that look like the errors below

iOS

  • Follow the setup from State Restoration on iOS in https://api.flutter.dev/flutter/services/RestorationManager-class.html
  • Change the scheme from debug to release in xcode
  • Run the app on a physical device in xcode
  • Tap on the "open counter" button and click on the FAB on the next page to set some values in the counter
  • Background the Flutter app and stop the app in xcode
  • Open the app from the menu
  • You should see a blank screen.

I suspect you should get the same error as you would on android. I attempted to attach to the Runner in xcode to see if I could get any logs but I had no success there.

E/flutter (22324): [ERROR:flutter/lib/ui/dart_runtime_hooks.cc(38)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/shell/common/shell.cc(89)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/lib/ui/dart_runtime_hooks.cc(38)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/shell/common/shell.cc(89)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/lib/ui/dart_runtime_hooks.cc(38)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/shell/common/shell.cc(89)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/lib/ui/dart_runtime_hooks.cc(38)] Dart Error: Class '_MyHomeState' not found in library ''.
E/flutter (22324): [ERROR:flutter/shell/common/shell.cc(89)] Dart Error: Class '_MyHomeState' not found in library ''.
code sample
import 'package:flutter/foundation.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(
      restorationScopeId: 'app',
      home: Banner(
        message: kDebugMode ? 'DEBUG' : 'RELEASE',
        location: BannerLocation.topEnd,
        child: Scaffold(
          appBar: AppBar(title: const Text('RestorableRouteFuture Example')),
          body: const MyHome(),
        ),
      ),
    );
  }
}

class MyHome extends StatefulWidget {
  const MyHome({super.key});

  @override
  State<MyHome> createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> with RestorationMixin {
  final RestorableInt _lastCount = RestorableInt(0);
  late RestorableRouteFuture<int> _counterRoute;

  @override
  String get restorationId => 'home';

  @override
  void initState() {
    super.initState();
    _counterRoute = RestorableRouteFuture<int>(onPresent: (NavigatorState navigator, Object? arguments) {
      // Defines what route should be shown (and how it should be added
      // to the navigator) when `RestorableRouteFuture.present` is called.
      return navigator.restorablePush(
        _counterRouteBuilder,
        arguments: arguments,
      );
    }, onComplete: (int count) {
      // Defines what should happen with the return value when the route
      // completes.
      setState(() {
        _lastCount.value = count;
      });
    });
  }

  @override
  void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
    // Register the `RestorableRouteFuture` with the state restoration framework.
    registerForRestoration(_counterRoute, 'route');
    registerForRestoration(_lastCount, 'count');
  }

  @override
  void dispose() {
    super.dispose();
    _lastCount.dispose();
    _counterRoute.dispose();
  }

  // A static `RestorableRouteBuilder` that can re-create the route during
  // state restoration.
  static Route<int> _counterRouteBuilder(BuildContext context, Object? arguments) {
    return MaterialPageRoute<int>(
      builder: (BuildContext context) => MyCounter(
        title: arguments!.toString(),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text('Last count: ${_lastCount.value}'),
          ElevatedButton(
            onPressed: () {
              // Show the route defined by the `RestorableRouteFuture`.
              _counterRoute.present('Awesome Counter');
            },
            child: const Text('Open Counter'),
          ),
        ],
      ),
    );
  }
}

// Widget for the route pushed by the `RestorableRouteFuture`.
class MyCounter extends StatefulWidget {
  const MyCounter({super.key, required this.title});

  final String title;

  @override
  State<MyCounter> createState() => _MyCounterState();
}

class _MyCounterState extends State<MyCounter> with RestorationMixin {
  final RestorableInt _count = RestorableInt(0);

  @override
  String get restorationId => 'counter';

  @override
  void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
    registerForRestoration(_count, 'count');
  }

  @override
  void dispose() {
    super.dispose();
    _count.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        leading: BackButton(
          onPressed: () {
            // Return the current count of the counter from this route.
            Navigator.of(context).pop(_count.value);
          },
        ),
      ),
      body: Center(
        child: Text('Count: ${_count.value}'),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        onPressed: () {
          setState(() {
            _count.value++;
          });
        },
      ),
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale en-GB)
    • Flutter version 3.3.10 on channel stable at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.74.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.56.0

[✓] Connected device (3 available)
    • Nexus (mobile)  • 00008020-001875E83A38002E • ios            • iOS 16.2 20C65
    • macOS (desktop) • macos                     • darwin-arm64   • macOS 13.1 22C65 darwin-arm
    • Chrome (web)    • chrome                    • web-javascript • Google Chrome 109.0.5414.87
    ! Error: Nexus is busy: Fetching debug symbols for Nexus. Xcode will continue when Nexus is finished. (code -10)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.
[!] Flutter (Channel master, 3.7.0-21.0.pre.44, on macOS 13.1 22C65 darwin-arm64, locale en-GB)
    • Flutter version 3.7.0-21.0.pre.44 on channel master at /Users/nexus/dev/sdks/flutters
    ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8c2fdb803e (19 hours ago), 2023-01-16 11:51:11 +0000
    • Engine revision f790304409
    • Dart version 3.0.0 (build 3.0.0-122.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.74.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.56.0

[✓] Connected device (3 available)
    • Nexus (mobile)  • 00008020-001875E83A38002E • ios            • iOS 16.2 20C65
    • macOS (desktop) • macos                     • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
    • Chrome (web)    • chrome                    • web-javascript • Google Chrome 109.0.5414.87

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 3 categories.

@danagbemava-nc danagbemava-nc added engine flutter/engine repository. See also e: labels. dependency: dart Dart team may need to help us has reproducible steps The issue has been confirmed reproducible and is ready to work on a: state restoration RestorationManager and related APIs found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 c: crash Stack traces logged to the console a: release Challenges faced when attempting to productionize an app and removed in triage Presently being triaged by the triage team labels Jan 17, 2023
@mraleph
Copy link
Member

mraleph commented Jan 17, 2023

This is most definitely related to stronger tree-shaking - you can't expect to reflectively access any functions or classes from native side unless they are marked with @pragma('vm:entry-point'). It seems that current design of state restoration does not account for that /cc @goderbauer

@chinmaygarde chinmaygarde removed the engine flutter/engine repository. See also e: labels. label Jan 17, 2023
@goderbauer goderbauer self-assigned this Jan 18, 2023
@goderbauer goderbauer added the framework flutter/packages/flutter repository. See also f: labels. label Jan 18, 2023
@danagbemava-nc danagbemava-nc added the r: fixed Issue is closed as already fixed in a newer version label Jan 19, 2023
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: release Challenges faced when attempting to productionize an app a: state restoration RestorationManager and related APIs c: crash Stack traces logged to the console dependency: dart Dart team may need to help us found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants