Skip to content

Flutter --analyze-build on Mac ARM only builds crashes with PathNotFoundException: Cannot open file #140659

@bvoq

Description

@bvoq

Steps to reproduce

First create any flutter app with macOS support enabled and make sure your macOS build only targets the ARM architecture (see the image):
image

If you run the below command (with or without --code-size-directory appsize)
flutter build macos --release --build-number 1 --analyze-size --code-size-directory appsize

the following files are correctly generated in the appsize directory:
snapshot.arm64.json
trace.arm64.json

So far so good, however that same command crashes with the following error:
Oops; flutter has exited unexpectedly: "PathNotFoundException: Cannot open file, path = 'appsize/snapshot.x86_64.json' (OS Error: No such file or directory, errno = 2)".
and will not show the statistics anymore.

Sometimes you have to remove the build folder using rm -rf build to trigger the error because it still builds for x64 for some reason.

Expected results

No crash on the Flutter command.

Actual results

Crash with the following error:
Oops; flutter has exited unexpectedly: "PathNotFoundException: Cannot open file, path = 'appsize/snapshot.x86_64.json' (OS Error: No such file or directory, errno = 2)".

Code sample

Code sample
import 'package:flutter/material.dart';

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

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

  // 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 THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // 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
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @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(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // 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.
          //
          // 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).
          //
          // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
          // action in the IDE, or press "p" in the console), to see the
          // wireframe for each widget.
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
compressedvid.mp4

Logs

Logs
#0      _File.throwIfError (dart:io/file_impl.dart:675:7)
#1      _File.openSync (dart:io/file_impl.dart:490:5)
#2      _File.readAsBytesSync (dart:io/file_impl.dart:574:18)
#3      _File.readAsStringSync (dart:io/file_impl.dart:624:18)
#4      ForwardingFile.readAsStringSync (package:file/src/forwarding/forwarding_file.dart:99:16)
#5      ErrorHandlingFile.readAsStringSync.<anonymous closure> (package:flutter_tools/src/base/error_handling_io.dart:218:22)
#6      _runSync (package:flutter_tools/src/base/error_handling_io.dart:590:14)
#7      ErrorHandlingFile.readAsStringSync (package:flutter_tools/src/base/error_handling_io.dart:217:12)
#8      SizeAnalyzer.analyzeAotSnapshot (package:flutter_tools/src/base/analyze_size.dart:57:64)
#9      buildMacOS (package:flutter_tools/src/macos/build_macos.dart:160:60)
<asynchronous suspension>
#10     BuildMacosCommand.runCommand (package:flutter_tools/src/commands/build_macos.dart:62:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1350:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:348:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:294:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:112:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>

Flutter Doctor output

Doctor output
�[33m[!]�[39m Flutter (Channel [user-branch], 3.16.3, on macOS 14.2 23C64 darwin-arm64, locale en-CH)
    �[33m!�[39m Flutter version 3.16.3 on channel [user-branch] at /Users/deke/Developer/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    �[33m!�[39m Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    �[32m•�[39m Framework revision b0366e0a3f (3 weeks ago), 2023-12-05 19:46:39 -0800
    �[32m•�[39m Engine revision 54a7145303
    �[32m•�[39m Dart version 3.2.3
    �[32m•�[39m DevTools version 2.28.4
    �[32m•�[39m If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and
      upgrades.

�[32m[✓]�[39m Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    �[32m•�[39m Android SDK at /Users/deke/Library/Android/sdk
    �[32m•�[39m Platform android-34, build-tools 33.0.0
    �[32m•�[39m ANDROID_HOME = /Users/deke/Library/Android/sdk
    �[32m•�[39m Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    �[32m•�[39m Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    �[32m•�[39m All Android licenses accepted.

�[32m[✓]�[39m Xcode - develop for iOS and macOS (Xcode 15.1)
    �[32m•�[39m Xcode at /Applications/Xcode.app/Contents/Developer
    �[32m•�[39m Build 15C65
    �[32m•�[39m CocoaPods version 1.14.3

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

�[32m[✓]�[39m Android Studio (version 2022.3)
    �[32m•�[39m Android Studio at /Applications/Android Studio.app/Contents
    �[32m•�[39m Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    �[32m•�[39m Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    �[32m•�[39m Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

�[32m[✓]�[39m IntelliJ IDEA Community Edition (version 2022.2.3)
    �[32m•�[39m IntelliJ at /Applications/IntelliJ IDEA CE.app
    �[32m•�[39m Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    �[32m•�[39m Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

�[32m[✓]�[39m VS Code (version 1.86.0-insider)
    �[32m•�[39m VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    �[32m•�[39m Flutter extension version 3.78.0

�[32m[✓]�[39m Connected device (3 available)
    �[32m•�[39m iPhone (6) (mobile) • 00008110-000A59682280401E • ios            • iOS 17.2 21C62
    �[32m•�[39m macOS (desktop)     • macos                     • darwin-arm64   • macOS 14.2 23C64 darwin-arm64
    �[32m•�[39m Chrome (web)        • chrome                    • web-javascript • Google Chrome 115.0.5790.114

�[32m[✓]�[39m Network resources
    �[32m•�[39m All expected network resources are available.

�[33m!�[39m Doctor found issues in 1 category.

Metadata

Metadata

Labels

P1High-priority issues at the top of the work lista: buildBuilding flutter applications with the toolc: crashStack traces logged to the consolefound in release: 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-macBuilding on or for macOS specificallyr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

Status

Future bugs/improvements

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions