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

Skip to content

Building Flutter projects on MacOS fails if FlutterMacOS.framwork is read-only (ie. in a Nix environment) #147142

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
asyncmeow opened this issue Apr 21, 2024 · 4 comments · Fixed by #148580
Labels
a: build Building flutter applications with the tool a: desktop Running on desktop platform-mac Building on or for macOS specifically r: fixed Issue is closed as already fixed in a newer version team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@asyncmeow
Copy link

asyncmeow commented Apr 21, 2024

Steps to reproduce

  1. Make sure nix is installed on your MacOS machine
  2. Run nix-shell -p flutter to create a shell with Flutter in your environment
  3. Attempt to build a project for MacOS with flutter build macos and notice how it fails
  4. Leave the nix environment you created in step 2 (exit)
  5. Attempt to build again for MacOS with flutter build macos and notice how it succeeds

Expected results

The build should succeed under the nix environment.

Actual results

The build fails on the nix environment due to FlutterMacOS.framework being read-only in the Nix store. The Nix store is intentionally read-only, so changing FlutterMacOS.framework to rw within the Nix store would ruin the point of using Nix here.

Code sample

Code sample As this issue occurs on the brand-new project created by `dart create bug`, I attached that file unmodified:
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

No response

Logs

Logs
underworld:bug pearl$ flutter build macos

2024-04-21 16:23:38.484 xcodebuild[49965:156303515] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-001230823E7A401E }
{ platform:macOS, arch:x86_64, id:00006000-001230823E7A401E }
Building App.framework for x86_64...
Building App.framework for arm64...
Target release_unpack_macos failed: Exception: Failed to extract arm64 x86_64 for /Users/pearl/code/test/bug/build/macos/Build/Products/Release/FlutterMacOS.framework/Versions/A/FlutterMacOS.
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't create temporary output file: /Users/pearl/code/test/bug/build/macos/Build/Products/Release/FlutterMacOS.framework/Versions/A/FlutterMacOS.lipo (Permission denied)

Running lipo -info:
Architectures in the fat file: /Users/pearl/code/test/bug/build/macos/Build/Products/Release/FlutterMacOS.framework/Versions/A/FlutterMacOS are: x86_64 arm64 


Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

Building macOS application...                                           
Build process failed
underworld:bug pearl$ 

Flutter Doctor output

Doctor output
underworld:bug pearl$ flutter doctor -v
[✓] Flutter (Channel stable, 3.19.0, on macOS 13.4.1 22F770820d darwin-arm64, locale en-US)
    • Flutter version 3.19.0 on channel stable at /nix/store/yj4imxhd3lcv6gjvv584ggchqy9k4krx-flutter-wrapped-3.19.0-sdk-links
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision nixpkgs000 (), 1970-01-01 00:00:00
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /nix/store/z0mkx48izmj3iv10p3ig4ij2qd3iq1j7-androidsdk/libexec/android-sdk
    • Platform android-34, build-tools 30.0.3
    • ANDROID_HOME = /nix/store/z0mkx48izmj3iv10p3ig4ij2qd3iq1j7-androidsdk/libexec/android-sdk
    • Java binary at: /Users/pearl/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

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

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2023.2)
    • Android Studio at /Users/pearl/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
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.4)
    • IntelliJ at /Users/pearl/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 78.4.2
    • Dart plugin version 233.15123

[✓] IntelliJ IDEA Community Edition (version 2024.1)
    • IntelliJ at /Users/pearl/94w87dhc6smqxdlq61kvy2ksd99j1fhw-idea-community-2024.1/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

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1)
    • IntelliJ at /Users/pearl/z9dfy1vs6g4gybvznyqlxn6453mgsy4z-idea-ultimate-2024.1/Applications/IntelliJ IDEA.app
    • Flutter plugin version 79.0.3
    • Dart plugin version 241.15845

[✓] VS Code (version 1.88.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-arm64 • macOS 13.4.1 22F770820d darwin-arm64

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

! Doctor found issues in 2 categories.
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Apr 22, 2024
@darshankawar
Copy link
Member

Thanks for the report and potential fix. I'll keep the issue open since this is related to Nix environment / setup which is external to the framework.

@darshankawar darshankawar added tool Affects the "flutter" command-line tool. See also t: labels. platform-mac Building on or for macOS specifically a: desktop Running on desktop team-tool Owned by Flutter Tool team a: build Building flutter applications with the tool and removed in triage Presently being triaged by the triage team labels Apr 22, 2024
@christopherfujino
Copy link
Contributor

cc @vashworth

@nilsreichardt
Copy link
Contributor

@asyncmeow You can try if this workaround works for you: #148354 (comment)

LouiseHsu added a commit that referenced this issue May 20, 2024
…erMacOS.framework (#148580)

Fixes #148354

Fixes #147142
Closes #147144

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this issue May 20, 2024
…erMacOS.framework (flutter#148580)

Fixes flutter#148354

Fixes flutter#147142
Closes flutter#147144

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label May 21, 2024
auto-submit bot pushed a commit that referenced this issue May 21, 2024
…k and FlutterMacOS.framework (#148717)

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

### Issue Link:
What is the link to the issue this cherry-pick is addressing?
#148354
#147142

### Changelog Description:
Correct read/write permisions for FlutterMacOS.framework to allow MacOS developers to publish to the app store

### Impact Description:
MacOS developers.

### Workaround:
Is there a workaround for this issue?

Run chmod locally after building #148354 (comment)

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
What are the steps to validate that this fix works?

1. `flutter build macos --release` any macos project
2. `ls -la macos/Build/Products/Release/test_create.app/Contents/Frameworks/`
3. Note that the permissions for FlutterMacOS.framework is `drwxr-xr-x`, NOT `dr-------`
(note that this is validated to work here #148354 (comment))
Copy link

github-actions bot commented Jun 4, 2024

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 Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: build Building flutter applications with the tool a: desktop Running on desktop platform-mac Building on or for macOS specifically r: fixed Issue is closed as already fixed in a newer version team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
4 participants