我可以在“C:\Users\pc\AppData\Local\Android\flutter\bin”路径运行“flutter”命令。但是在尝试生成 APK 时,如果我更改项目根目录的路径,“flutter”命令将不起作用。
我已经添加了环境变量的所有路径,如其他各种问题中提到的,包括:
C:\Users\pc\AppData\Local\Android\flutter\bin
C:\Program Files\Android\Android Studio\jre\bin\java
C:\Program Files\Git\bin
如果我将 Android Studio 中的终端路径更改为“C:\Users\pc\AppData\Local\Android\flutter\bin”,则“flutter”命令工作正常。我能够运行像“flutter -doctor”这样的命令。
但是,当我尝试使用“flutter build apk”生成用于发布的 apk 时,我使用的是终端中设置的默认路径,即项目的根目录。它说:
'flutter' is not recognized as an internal or external command, operable program or batch file.
如果我尝试在“C:\Users\pc\AppData\Local\Android\flutter\bin”中运行相同的命令,输出为:
Error: No pubspec.yaml file found. This command should be run from the root of your Flutter project. Do not run this command from the root of your git clone of Flutter.
如果有人可以向我建议使其工作的东西,那将非常有帮助。
最佳答案
我仍然无法通过 Android Studio 内的终端在我的项目根目录中运行诸如“flutter run”或“flutter build apk”之类的命令。
但是,这些相同的命令在 flutter sdk 文件夹中的 flutter_console.bat 中运行时运行良好。
因此,使用 flutter_console.bat ,我只需更改项目根目录的路径并使用“flutter build apk --release”命令生成 apk。
关于windows - 'flutter' 命令在项目的根目录中不起作用。 [ Windows ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55668378/