Skip to content

Asset paths are inconsistent  #84346

Description

@hitman-codehq

Steps to Reproduce

  1. Run flutter create asset_example.
  2. Update the files as follows: Extract the attached file:
    asset_example.zip
  3. This file adds an asset called my_asset.txt and some code to try and read it in lib/main.dart
  4. Run the build on Windows with "flutter run" and select the target Windows (desktop)
  5. Click on the FAB and look at the console output

Expected results:

The code called by clicking on the FAB, in lib/main.dart:_readAssest(), should print:

flutter: *** Test #1: Calling loadString() without path
flutter: *** Success (Hello world)!
flutter: ***
flutter: *** Test #2: Calling loadString() with path
flutter: *** Success (Hello world)!

Actual results:

flutter: *** Test #1: Calling loadString() without path
flutter: *** Failed, exception thrown
flutter: ***
flutter: *** Test #2: Calling loadString() with path
flutter: *** Success (Hello world)!

This only happens on Windows. On MacOS, Android, iOS and Web (both on Windows and MacOS) it doesn't matter whether you call loadString('my_asset.txt') or loadString('assets/my_asset.txt'). The behaviour should be consistent across all platforms. It took quite a bit of digging to figure out why a 3rd party plugin wasn't working on Windows due to this problem!

If you now type "flutter run" and instead select Chrome (chrome) as the target, you'll see that both calls to loadString() work.

It doesn't matter whether I add the asset to the pubspec.yaml by using the full path (- assets/my_asset.txt) or only the filename (- my_asset.txt): the results are the same. I have to use the full path in loadString() for it to work on Windows but on all other platforms, just the filename is enough.

Logs
[Snipped excessive output]
[   +2 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/assets
[   +2 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/**assets/my_asset.txt**
[   +3 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/FontManifest.json
[   +2 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/fonts
[   +1 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/fonts/MaterialIcons-Regular.otf
[  +24 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/kernel_blob.bin
[ +488 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/NOTICES
[ +280 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages
[   +1 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages/cupertino_icons
[   +2 ms]   -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages/cupertino_icons/assets
[   +2 ms]   -- Installing:
D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf
[  +39 ms] FinalizeBuildStatus:
[   +1 ms]   Die Datei "x64\Debug\INSTALL\INSTALL.tlog\unsuccessfulbuild" wird gelöscht.
[        ]   Aktualisieren des Timestamps von "x64\Debug\INSTALL\INSTALL.tlog\INSTALL.lastbuildstate".
[        ] Die Erstellung von Projekt "D:\Source\Flutter\asset_example\build\windows\INSTALL.vcxproj" ist abgeschlossen (Standardziele).
[        ] Der Buildvorgang wurde erfolgreich ausgeführt.
[   +1 ms]     0 Warnung(en)
[        ]     0 Fehler
[        ] Verstrichene Zeit 00:00:47.41
[  +39 ms] Building Windows application... (completed in 53,5s)
[+1925 ms] Observatory URL on device: http://127.0.0.1:60977/jbP5Nn4c03M=/
[   +5 ms] Caching compiled dill
[  +66 ms] Connecting to service protocol: http://127.0.0.1:60977/jbP5Nn4c03M=/
[ +212 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:60977/jbP5Nn4c03M=/.
[  +80 ms] DDS is listening at http://127.0.0.1:60980/j2QIYS1vN84=/.
[  +73 ms] Successfully connected to service protocol: http://127.0.0.1:60977/jbP5Nn4c03M=/
[  +23 ms] DevFS: Creating new filesystem on the device (null)
[  +21 ms] DevFS: Created new filesystem on the device (file:///C:/Users/Colin/AppData/Local/Temp/asset_examplecadd69ff/asset_example/)
[   +2 ms] Updating assets
[  +91 ms] Syncing files to device Windows...
[   +3 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[   +3 ms] <- recompile package:asset_example/main.dart 76b568cb-07ad-4824-bfb4-e0a0852698a8
[        ] <- 76b568cb-07ad-4824-bfb4-e0a0852698a8
[ +249 ms] Updating files.
[   +1 ms] DevFS: Sync finished
[        ] Syncing files to device Windows... (completed in 258ms)
[        ] Synced 0.0MB.
[   +2 ms] <- accept
[   +7 ms] Connected to _flutterView/0x16d800d0ec0.
[   +4 ms] Flutter run key commands.
[   +1 ms] r Hot reload.
[   +1 ms] R Hot restart.
[        ] h Repeat this help message.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[        ] q Quit (terminate the application on the device).
[        ]  Running with sound null safety
[        ] An Observatory debugger and profiler on Windows is available at: http://127.0.0.1:60980/j2QIYS1vN84=/
[+1596 ms] The Flutter DevTools debugger and profiler on Windows is available at:
http://127.0.0.1:9108?uri=http%3A%2F%2F127.0.0.1%3A60980%2Fj2QIYS1vN84%3D%2F
[+2089 ms] flutter: *** Test #1: Calling loadString() without path
[  +10 ms] flutter: *** Failed, exception thrown
[        ] flutter: ***
[        ] flutter: *** Test #2: Calling loadString() with path
[   +1 ms] flutter: *** Success (Hello world)!
d:\Source\Flutter\asset_example>flutter analyze
Analyzing asset_example...
No issues found! (ran in 19.3s)
d:\Source\Flutter\asset_example>flutter doctor -v
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19041.1052], locale de-DE)
    • Flutter version 2.2.1 at d:\Coding\Flutter
    • Framework revision 02c026b03c (2 weeks ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at d:\Coding\Android\SDK
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
    • All Android licenses accepted.

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

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.0)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.10.31321.278
    • Windows 10 SDK version 10.0.19041.0

[!] 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/windows#android-setup for detailed instructions).

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

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19041.1052]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 91.0.4472.77
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 91.0.864.41

! Doctor found issues in 1 category.

Many thanks for your help!

Activity

  1. TahaTesser commented on Jun 11, 2021

    @TahaTesser
    Contributor

    Hi @hitman-codehq
    The issue is your pubspec.yaml, you're missing path for var assetContent = await rootBundle.loadString('my_asset.txt'); and place the my_asset.txt file in the root directory of your project

    minimal code sample
    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart' show rootBundle;
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            // This is the theme of your application.
            //
            // Try running your application with "flutter run". You'll see the
            // application has a blue toolbar. Then, without quitting the app, try
            // changing the primarySwatch below to Colors.green and then invoke
            // "hot reload" (press "r" in the console where you ran "flutter run",
            // or simply save your changes to "hot reload" in a Flutter IDE).
            // Notice that the counter didn't reset back to zero; the application
            // is not restarted.
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key? key, required this.title}) : super(key: key);
    
      // This widget is the home page of your application. It is stateful, meaning
      // that it has a State object (defined below) that contains fields that affect
      // how it looks.
    
      // This class is the configuration for the state. It holds the values (in this
      // case the title) provided by the parent (in this case the App widget) and
      // used by the build method of the State. Fields in a Widget subclass are
      // always marked "final".
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0;
    
      void _readAsset() async {
        try {
          print('*** Test #1: Calling loadString() without path');
          var assetContent = await rootBundle.loadString('my_asset.txt');
          print('*** Success ($assetContent)!');
        } on FlutterError {
          print('*** Failed, exception thrown');
        }
    
        try {
          print('***');
          print('*** Test #2: Calling loadString() with path');
          var assetContent = await rootBundle.loadString('assets/my_asset.txt');
          print('*** Success ($assetContent)!');
        } on FlutterError {
          print('*** Failed, exception thrown');
        }
      }
    
      @override
      Widget build(BuildContext context) {
        // This method is rerun every time setState is called, for instance as done
        // by the _incrementCounter method above.
        //
        // The Flutter framework has been optimized to make rerunning build methods
        // fast, so that you can just rebuild anything that needs updating rather
        // than having to individually change instances of widgets.
        return Scaffold(
          appBar: AppBar(
            // Here we take the value from the MyHomePage object that was created by
            // the App.build method, and use it to set our appbar title.
            title: Text(widget.title),
          ),
          body: Center(
            // Center is a layout widget. It takes a single child and positions it
            // in the middle of the parent.
            child: Column(
              // Column is also a layout widget. It takes a list of children and
              // arranges them vertically. By default, it sizes itself to fit its
              // children horizontally, and tries to be as tall as its parent.
              //
              // Invoke "debug painting" (press "p" in the console, choose the
              // "Toggle Debug Paint" action from the Flutter Inspector in Android
              // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
              // to see the wireframe for each widget.
              //
              // Column has various properties to control how it sizes itself and
              // how it positions its children. Here we use mainAxisAlignment to
              // center the children vertically; the main axis here is the vertical
              // axis because Columns are vertical (the cross axis would be
              // horizontal).
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'You have pushed the button this many times:',
                ),
                Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _readAsset,
            tooltip: 'Increment',
            child: Icon(Icons.add),
          ), // This trailing comma makes auto-formatting nicer for build methods.
        );
      }
    }
    
    [   +2 ms] Flutter run key commands.
    [   +1 ms] r Hot reload. 🔥🔥🔥
    [   +1 ms] R Hot restart.
    [        ] h Repeat this help message.
    [        ] d Detach (terminate "flutter run" but leave application running).
    [        ] c Clear the screen
    [        ] q Quit (terminate the application on the device).
    [        ] 💪 Running with sound null safety 💪
    [        ] An Observatory debugger and profiler on Windows is available at: http://127.0.0.1:56935/4P_9Z-UaY28=/
    [ +704 ms] The Flutter DevTools debugger and profiler on Windows is available at:
                        http://127.0.0.1:9105?uri=http%3A%2F%2F127.0.0.1%3A56935%2F4P_9Z-UaY28%3D%2F
    [+4738 ms] flutter: *** Test #1: Calling loadString() without path
    [  +14 ms] flutter: *** Success (Hello world)!
    [   +1 ms] flutter: ***
    [        ] flutter: *** Test #2: Calling loadString() with path
    [   +1 ms] flutter: *** Success (Hello world)
    pubspec.yaml
    name: asset_example
    description: A new Flutter project.
    
    # The following line prevents the package from being accidentally published to
    # pub.dev using `pub publish`. This is preferred for private packages.
    publish_to: 'none' # Remove this line if you wish to publish to pub.dev
    
    # The following defines the version and build number for your application.
    # A version number is three numbers separated by dots, like 1.2.43
    # followed by an optional build number separated by a +.
    # Both the version and the builder number may be overridden in flutter
    # build by specifying --build-name and --build-number, respectively.
    # In Android, build-name is used as versionName while build-number used as versionCode.
    # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
    # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
    # Read more about iOS versioning at
    # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
    version: 1.0.0+1
    
    environment:
      sdk: ">=2.12.0 <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter
    
    
      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
      cupertino_icons: ^1.0.2
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    # For information on the generic Dart part of this file, see the
    # following page: https://dart.dev/tools/pub/pubspec
    
    # The following section is specific to Flutter.
    flutter:
    
      # The following line ensures that the Material Icons font is
      # included with your application, so that you can use the icons in
      # the material Icons class.
      uses-material-design: true
    
      # To add assets to your application, add an assets section, like this:
      assets:
        - assets/my_asset.txt
        - my_asset.txt
    
    
      #   - images/a_dot_burr.jpeg
      #   - images/a_dot_ham.jpeg
    
      # An image asset can refer to one or more resolution-specific "variants", see
      # https://flutter.dev/assets-and-images/#resolution-aware.
    
      # For details regarding adding assets from package dependencies, see
      # https://flutter.dev/assets-and-images/#from-packages
    
      # To add custom fonts to your application, add a fonts section here,
      # in this "flutter" section. Each entry in this list should have a
      # "family" key with the font family name, and a "fonts" key with a
      # list giving the asset and other descriptors for the font. For
      # example:
      # fonts:
      #   - family: Schyler
      #     fonts:
      #       - asset: fonts/Schyler-Regular.ttf
      #       - asset: fonts/Schyler-Italic.ttf
      #         style: italic
      #   - family: Trajan Pro
      #     fonts:
      #       - asset: fonts/TrajanPro.ttf
      #       - asset: fonts/TrajanPro_Bold.ttf
      #         weight: 700
      #
      # For details regarding fonts from package dependencies,
      # see https://flutter.dev/custom-fonts/#from-packages
    

    image

    Closing, as this isn't an issue with Flutter itself. If you disagree, please write in the comments and I will reopen it.
    Thank you

  2. added
    r: invalidIssue is closed as not valid
    and removed
    in triagePresently being triaged by the triage team
    on Jun 11, 2021
  3. hitman-codehq commented on Jun 28, 2021

    @hitman-codehq
    Author

    Hello @TahaTesser, just getting back to this issue again.

    Yes your solution would of course work, but the problem here is that the solution is only required on Windows. It works just fine on the other platforms that are supported by Flutter without having to change my .dart code or move the asset. So it should also work on Windows without having to do that.

    So it would be appreciated if you could re-open this issue and address it, as I lost quite a bit of time due to this, and other people have as well.

    Many thanks.

  4. hitman-codehq commented on Jul 6, 2021

    @hitman-codehq
    Author

    @TahaTesser can we re-open this issue please? I spent quite some time making a reproducible test case and it would be nice to see it fixed.

  5. added
    in triagePresently being triaged by the triage team
    and removed
    r: invalidIssue is closed as not valid
    on Jul 9, 2021
  6. TahaTesser commented on Jul 12, 2021

    @TahaTesser
    Contributor

    Hi @hitman-codehq
    I just tried on macOS too, error is thrown since you're not providing correct path

    [   +6 ms] Connected to _flutterView/0x7fbc83050820.
    [   +2 ms] Flutter run key commands.
    [   +1 ms] r Hot reload. 🔥🔥🔥
    [   +1 ms] R Hot restart.
    [        ] h Repeat this help message.
    [        ] d Detach (terminate "flutter run" but leave application running).
    [        ] c Clear the screen
    [        ] q Quit (terminate the application on the device).
    [        ] 💪 Running with sound null safety 💪
    [        ] An Observatory debugger and profiler on macOS is available at:
    http://127.0.0.1:50001/A4B3rk64kp4=/
    [ +797 ms] The Flutter DevTools debugger and profiler on macOS is available at:
                        http://127.0.0.1:9100?uri=http%3A%2F%2F127.0.0.1%3A50001%2FA4B3rk64kp4%3D%2F
    [+14193 ms] flutter: *** Test #1: Calling loadString() without path
    [  +13 ms] flutter: *** Failed, exception thrown
    [        ] flutter: ***
    [        ] flutter: *** Test #2: Calling loadString() with path
    [   +2 ms] flutter: *** Success (Hello world)!
    

    await rootBundle.loadString('my_asset.txt'); is looking for a file in app root directory hence the error

    If you correct the path and put file in root directory too

      assets:
        - my_asset.txt
        - assets/my_asset.txt
    

    The error is gone on macOS too

    [        ] An Observatory debugger and profiler on macOS is available at:
    http://127.0.0.1:50151/0Wba8YDUcFI=/
    [ +763 ms] The Flutter DevTools debugger and profiler on macOS is available at:
                        http://127.0.0.1:9102?uri=http%3A%2F%2F127.0.0.1%3A50151%2F0Wba8YDUcFI%3D%2F
    [+114152 ms] flutter: *** Test #1: Calling loadString() without path
    [  +12 ms] flutter: *** Success (Hello world)!
    [        ] flutter: ***
    [        ] flutter: *** Test #2: Calling loadString() with path
    [        ] flutter: *** Success (Hello world)!
  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 12, 2021
  8. hitman-codehq commented on Jul 13, 2021

    @hitman-codehq
    Author

    Hello @TahaTesser I have done some more tests and it seems that with Flutter 2.2.3 the behaviour has changed. On MacOS, the failure is also happening now. And that is ok, because it is the same result as on Windows.

    So good, with Flutter 2.2.3 it is now working the same on Windows and MacOS for native Flutter apps. But let's try it on Windows or MacOS with Chrome as the target:

    *** Test #1: Calling loadString() without path
    *** Success (Hello world)!
    ***
    *** Test #2: Calling loadString() with path
    *** Success (Hello world)!
    

    Oh no! They both work! But they shouldn't. Why? Because the behaviour should be the same on all platforms. That's the whole point of Flutter. Either both tests work on Windows, MacOS and Chrome (plus Android and iOS) or test #1 fails on all platforms and test #2 succeeds.

    Please don't tell me to edit my pubspec.yaml or main.dart because that's missing the point. It's not what this issue is about.

    Hopefully I've managed to explain better what the actual problem is.

    Interestingly there are no mentions of path or asset related issues on https://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel but the behaviour has definitely changed.

  9. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 13, 2021
  10. hitman-codehq commented on Jul 13, 2021

    @hitman-codehq
    Author

    A little bit more information why this is important. Have a look at this plugin:

    https://pub.dev/packages/flutter_dotenv

    I was using this and it was working if you follow its instructions on MacOS and Chrome. But it wasn't working on Windows. On the website of the plugin, lots of people are asking when Windows will be supported. But the thing is: it already is supported. But it wasn't working because Flutter on Windows was working differently to other platforms so the instructions weren't working.

    This highlights the importance of Flutter behaving identically on different platforms.

  11. 22 remaining items

  12. flutter-triage-bot commented on Aug 15, 2023

    @flutter-triage-bot

    Issue is assigned to multiple teams (engine, tool). Please ensure the issue has only one team-* label at a time. Use fyi-* labels to have another team look at the issue without reassigning it.

  13. added
    team-toolOwned by Flutter Tool team
    and removed
    engineflutter/engine related. See also e: labels.
    on Aug 15, 2023
  14. christopherfujino commented on Aug 15, 2023

    @christopherfujino
    Contributor

    @andrewkolos can you verify if this is still an issue, and then either close or mark triaged-tool with a priority?

  15. andrewkolos commented on Aug 15, 2023

    @andrewkolos
    Contributor

    I have not tried to reproduce the issue, but here is the short version of my understanding from skimming it...

    I was able to repro the issue using these steps. my_asset.txt was loadable in web, but not in Android or MacOS (and assumably all other platforms as well).

  16. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Aug 15, 2023
  17. hitman-codehq commented on Aug 16, 2023

    @hitman-codehq
    Author

    Thanks for looking into this. I remember I lost a bit of time due to this inconsistent behaviour, and then put quite a bit of effort into making a reproducible test case. It's only a small bug, but it would be nice to see it fixed. 👍

  18. added
    tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
    on Jul 10, 2025
  19. added a commit that references this issue on Aug 21, 2026
    7c0ccea
  20. github-actions commented on Sep 4, 2026

    @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.

  21. locked as resolved and limited conversation to collaborators on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: assetsPackaging, accessing, or using assetsfound in release: 2.2Found to occur in 2.2found in release: 2.4Found to occur in 2.4has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions