Repository navigation
Closed
Labels
r: solvedIssue is closed as solved
Description
Steps to reproduce
- Flutter version 3.19.6, stable channel.
- macOS Sonama 14.4.1 on Apple M2 Chip.
- Once create a new flutter app and run, it can hot restart or hot reload normally.
- Once the version code in
pub spec.yamlchanged, it cannot hot reload or hot restart. - Even if the version code changed back to the initial version code (
1.0.0+1) again, it still not cannot work. - I've tried many different app names, domains and even local positions, but all them failed again and again.
Expected results
In the previous versions, I can easily hot reload or hot restart whatever version code I have.
But in this version, once version code changed, it cannot hot reload or hot restart.
Actual results
Followings are the exception output:
Flutter failed to create file at
"/Users/aprosail/Library/Containers/com.example.hello/Data/tmp/helloCrWZCY/hello/main.dart.incremental.dill".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.I think that might be a conflict with Apple's security strategies, that macOS will block Flutter from command line
to modify such application when something changed.
Code sample
It's just the same as the template.
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
No response
Logs
Launching lib/main.dart on macOS in debug mode...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00001234-0001234567890ABE, name:My Mac }
{ platform:macOS, arch:x86_64, id:00001234-0001234567890ABE, name:My Mac }
Building macOS application...
Syncing files to device macOS... 45ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on macOS is available at: http://127.0.0.1:50005/CS__JsIRqV0=/
The Flutter DevTools debugger and profiler on macOS is available at: http://127.0.0.1:9107?uri=http://127.0.0.1:50005/CS__JsIRqV0=/
2024-05-20 00:24:13.907 hello[18429:6170078] WARNING: Secure coding is automatically enabled for restorable state! However, not on all supported macOS versions of this application. Opt-in to secure coding explicitly by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState:.
Performing hot reload...
Application finished.
Flutter failed to create file at
"/Users/aprosail/Library/Containers/com.example.hello/Data/tmp/helloCrWZCY/hello/main.dart.incremental.dill".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.89.1)
[✓] Connected device (2 available)
[✓] Network resources
! Doctor found issues in 1 category.Metadata
Metadata
Assignees
Labels
r: solvedIssue is closed as solved
Activity
aprosail commentedon May 19, 2024
This issue is similar to #139875 (which happened on VSCode but this happened even in macOS command line). That issue was closed, but I'm afraid that this problem is not finished yet.
aprosail commentedon May 19, 2024
I've update Flutter version to 3.22.0 but this problem still remains.
darshankawar commentedon May 20, 2024
Thanks for the report @aprosail
Although I don't have M2 and Sonoma OS, I tried on Intel on which I wasn't able to replicate the error.
Can you check this with underlying comments and see if they help in your case or not ?
mko15 commentedon May 20, 2024
Same here,
Apple M1 + Sonoma 14.2
Hot restart is not working on a clean app for the macOS platform. iOS and Android do not have this issue.
I've add permissions, tried Flutter 3.19.1 and 3.22.0, but nothing changed.
aprosail commentedon May 20, 2024
Thanks for your attention @darshankawar, and I've read the issue #70216 ,
but such solutions cannot be applied on macOS environment.
I guess that's not a problem about the chip, but the OS.
There might be some security strategy to prevent modifying executables or libraries (the
.dillfile)when such application is running.
The Flutter dev tool might be recognized as something like a virus,
and if so, there must be some way to allow such operations.
Please attention that I met such problem after the version code changed.
When running for the first few times without changing the initial version code, it still runs normally.
You can try it after changing the version code of the flutter app, or update to macOS Sonoma if possible.
I'm now running on Chrome as an alternative.
But there's still some platform specified code that I need to preview on macOS.
Rebuilding once and once again really takes much longer time than hot reload or hot restart.
aprosail commentedon May 20, 2024
@mko15 how do you "add permission"? I'm interested and I wanna to try it.
aprosail commentedon May 20, 2024
Well, I'm not a really skilled programmer that I cannot dive deep into Flutter's source code to fix such bug.
But there might be two solutions in my opinion, just for reference:
KevinBrendel commentedon May 20, 2024
For me, macOS had a popup asking me to give VS Code the ability to modify other apps when I tried to hot reload (and it worked afterwards). So this is something which can be allowed by the user, but not sure how to grant this permission without the popup.
aprosail commentedon May 20, 2024
Thanks a lot @KevinBrendel , I found a solution inspired by your words:
On macOS Sonoma, open System Settings > Privacy & Security > Full Disk Access, and allow for your code editor (such as VSCode or Android Studio) or the terminal, and then it can hot reload and hot restart. @mko15 , maybe you can try it.
However, there will be potential risk about such permission, especially when enabling for the terminal.
Sorry for taking your time @darshankawar , but I still recommend to add some mentions into official docs to let people know there might be such problem and how to solve it.
mko15 commentedon May 20, 2024
Yep, it works :) Thank you @aprosail
github-actions commentedon 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 -vand a minimal reproduction of the issue.