Skip to content

In widget tests after upgrading to Flutter 3.10.1, loading an asset results in Unable to load asset: "AssetManifest.smcbin" #127297

Description

@garrettlove8

Is there an existing issue for this?

Steps to reproduce

Not entirely sure what I did that caused this, and thus how to reproduce it. What I can for sure is,

  1. I upgraded to Flutter 3.10.1
  2. I have an assets directory in the root of my project
  3. The assets directory is connected to the app via my pubspec.yaml file like so:
assets:
    - assets/
  1. Running the app and navigating to the screen that uses these assets (images) works correctly
  2. Running Widget tests which navigate to screen that use these assets fail.

Expected results

Tests should pass.

Actual results

Tests fail with error:

══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown while resolving an image:
Unable to load asset: "AssetManifest.smcbin".
The asset does not exist or has empty data.

When the exception was thrown, this was the stack:
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:336:7)
#1      CachingAssetBundle.loadStructuredBinaryData (package:flutter/src/services/asset_bundle.dart:272:5)
#2      AssetManifest.loadFromAssetBundle (package:flutter/src/services/asset_manifest.dart:19:19)
#3      AssetImage.obtainKey (package:flutter/src/painting/image_resolution.dart:284:19)
#4      ScrollAwareImageProvider.obtainKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:118:74)
#5      ImageProvider._createErrorHandlerAndKey (package:flutter/src/painting/image_provider.dart:480:13)
#6      ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:371:5)
#7      _ImageState._resolveImage (package:flutter/src/widgets/image.dart:1111:16)
#8      _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:1061:5)
#9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5237:11)
#10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062:5)
...     Normal element mounting (7 frames)
#17     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#18     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#19     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (40 frames)
#59     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#60     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#61     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (105 frames)
#166    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#167    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#168    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (228 frames)
#396    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#397    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#398    Element.updateChild (package:flutter/src/widgets/framework.dart:3708:18)
#399    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:6153:32)
#400    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6595:17)
#401    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#402    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#403    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)
#404    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#405    StatefulElement.update (package:flutter/src/widgets/framework.dart:5274:5)
#406    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#407    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#408    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#409    ProxyElement.update (package:flutter/src/widgets/framework.dart:5417:5)
#410    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#411    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#412    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#413    ProxyElement.update (package:flutter/src/widgets/framework.dart:5417:5)
#414    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:107:11)
#415    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#416    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#417    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)
#418    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#419    StatefulElement.update (package:flutter/src/widgets/framework.dart:5274:5)
#420    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#421    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#422    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#423    ProxyElement.update (package:flutter/src/widgets/framework.dart:5417:5)
#424    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:107:11)
#425    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#426    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#427    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)
#428    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#429    StatefulElement.update (package:flutter/src/widgets/framework.dart:5274:5)
#430    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#431    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#432    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)
#433    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#434    StatefulElement.update (package:flutter/src/widgets/framework.dart:5274:5)
#435    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#436    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6442:14)
#437    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#438    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6442:14)
#439    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#440    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#441    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#442    ProxyElement.update (package:flutter/src/widgets/framework.dart:5417:5)
#443    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#444    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#445    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)
#446    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#447    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2780:19)
#448    AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1386:19)
#449    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:358:5)
#450    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1284:15)
#451    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1214:9)
#452    AutomatedTestWidgetsFlutterBinding.pump.<anonymous closure> (package:flutter_test/src/binding.dart:1236:9)
#455    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:68:41)
#456    AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:1222:27)
#457    WidgetTester.pumpAndSettle.<anonymous closure> (package:flutter_test/src/widget_tester.dart:709:23)
#460    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:68:41)
#461    WidgetTester.pumpAndSettle (package:flutter_test/src/widget_tester.dart:702:27)
#462    main.<anonymous closure> (file:///Users/garrettlove/Development/leifer/apps/mobile/test/widget_test/user_dispatch_screen_test.dart:287:18)
<asynchronous suspension>
<asynchronous suspension>
(elided 5 frames from dart:async and package:stack_trace)

Image provider: ScrollAwareImageProvider<Object>()
Image configuration: ImageConfiguration(bundle: PlatformAssetBundle#695da(), devicePixelRatio: 3.0,
  locale: en_US, textDirection: TextDirection.ltr, platform: android)
════════════════════════════════════════════════════════════════════════════════════════════════════
Test failed. See exception logs above.

Code sample

Code sample
  testWidgets('Tapping the "Delete Account" button, then "Yes" button, deletes the user\'s account and navigates to the Welcome screen', (WidgetTester tester) async {
    Environment().initConfig("SANDBOX");

    final mockObserver = MockNavigatorObserver();
    final mockAuthRepo = MockAuthRepository(firebaseAuth: mockAuth);
    final mockMetricsRepo = MockMetricsRepository();
    final firestore = FakeFirebaseFirestore();

    await tester.pumpWidget(ProviderScope(
      overrides: [
        authRepostoryProvider.overrideWith((ref) {
          return mockAuthRepo;
        }),
        firestoreProvider.overrideWith((ref) {
          return firestore;
        }),
        metricsProvider.overrideWith((ref) {
          return mockMetricsRepo;
        }),
      ],
      child: MaterialApp(
        routes: {
          '/welcome': (context) => const WelcomeScreen(),
        },
        home: const UserDispatchScreen(),
        navigatorObservers: [mockObserver],
      ),
    ));

    final deleteAccountFinder = find.text("Delete Account");
    await tester.scrollUntilVisible(deleteAccountFinder, 1.0);
    expect(deleteAccountFinder, findsOneWidget);

    await tester.tap(deleteAccountFinder);
    await tester.pumpAndSettle();

    final yesButtonFinder = find.text("Yes");
    await tester.tap(yesButtonFinder);
    await tester.pumpAndSettle();

    expect(find.byType(WelcomeScreen), findsOneWidget);
  });

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.1, on macOS 13.4 22F66 darwin-arm64, locale en-US)
    • Flutter version 3.10.1 on channel stable at /Users/garrettlove/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3d8effc68 (5 days ago), 2023-05-16 17:59:05 -0700
    • Engine revision b4fb11214d
    • Dart version 3.0.1
    • DevTools version 2.23.1

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


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

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

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

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

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 861DBD81-1790-42F6-9AE9-1690B0A960B9 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 113.0.5672.126

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

! Doctor found issues in 2 categories.

Activity

  1. remonh87 commented on May 22, 2023

    @remonh87

    I had same issue but fixed it by running flutter clean and flutter pub get

  2. garrettlove8 commented on May 22, 2023

    @garrettlove8
    Author

    @remonh87 That worked, thanks. I was under the impression that flutter clean and flutter pub get were specific to packages and since this seemed to be related project configuration I didn't think those would help.

  3. self-assigned this
    on May 22, 2023
  4. andrewkolos commented on May 22, 2023

    @andrewkolos
    Contributor

    Thanks for taking the time to file this issue.

    This is likely caused by #126837.

    7. Running the app and navigating to the screen that uses these assets (images) works correctly
    8. Running Widget tests which navigate to screen that use these assets fail.

    I had same issue but fixed it by running flutter clean and flutter pub get

    This is very interesting. flutter test does some interesting things in overriding the asset bundle, so it's possible that something is going wrong there.

    I'm reopening and assigning this to me now for some brief investigation to see if I can find a cause for this issue and perhaps prevent similar things in the future.

  5. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    a: assetsPackaging, accessing, or using assets
    on May 22, 2023
  6. rolandtolnay commented on May 23, 2023

    @rolandtolnay

    Encountering the same issue running my app on the iOS simulator (not tests).

    Same steps as above, was working fine with Flutter 3.10.0.
    First noticed it after upgrading to Flutter 3.10.1.

    Running flutter clean and flutter pub get fixed it for me as well

  7. AliEasy commented on Jun 7, 2023

    @AliEasy

    Running flutter clean and flutter pub get not working.
    Using flutter 3.10.2

    err

  8. changed the title [-]Unable to load asset: "AssetManifest.smcbin".[/-] [+]In widget tests after upgrading to Flutter 3.10.1, loading an asset results in `Unable to load asset: "AssetManifest.smcbin"`[/+] on Jun 7, 2023
  9. andrewkolos commented on Jun 7, 2023

    @andrewkolos
    Contributor

    Running flutter clean and flutter pub get not working. Using flutter 3.10.2

    err

    @AliEasy You might be running into #128230.

  10. AliEasy commented on Jun 8, 2023

    @AliEasy

    Running flutter clean and flutter pub get not working. Using flutter 3.10.2

    err

    You might be running into #128230.

    Problem solved. Thanks!

  11. andrewkolos commented on Jun 9, 2023

    @andrewkolos
    Contributor

    Repro steps

    1. Switch to flutter 3.7.
    2. Create a flutter project with an app that displays an image asset.
    3. Write a widget test (the one that is generated by the default flutter create template should be sufficient).
    4. Run the widget test. It should pass or at least not fail with an asset-related error message.
    5. Switch to flutter 3.10.1 (master also works, as of time of writing).
    6. Run the widget test again. You should see an error message containing a line similar to Unable to load asset: "AssetManifest.smcbin".

    Suspected cause

    In a discussion on the #hackers-tool Discord channel, @jonahwilliams theorized this issue might be caused by some special asset-related behavior in flutter test. This appears to be the case: flutter test has some code that determines whether or not the tool needs to rebuild the asset bundle, and part of that logic became out-of-date with #126837.

    bool _needRebuild(Map<String, DevFSContent> entries) {
    final File manifest = globals.fs.file(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.json'));
    if (!manifest.existsSync()) {
    return true;
    }

    In this code, we check to see if the asset manifest is missing, and we rebuild the bundle if it is. However, we use the old asset manifest (AssetManifest.json, which is still generated in 3.10) instead of the new one (AssetManifest.smcbin).

  12. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    P1High-priority issues at the top of the work list
    on Jun 9, 2023
  13. andrewkolos commented on Jun 9, 2023

    @andrewkolos
    Contributor

    Closing this issue as there is a known workaround (running flutter clean once, in each project) and #128563 tracks the underlying issue. If anyone is still running into this issue when running flutter test, please comment on this issue or open a new one.

    Thanks, everyone here, for your contributions 👍 .

  14. github-actions commented on Jun 23, 2023

    @github-actions

    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.

  15. locked as resolved and limited conversation to collaborators on Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: assetsPackaging, accessing, or using assetshas reproducible stepsThe issue has been confirmed reproducible and is ready to work ontoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions