Manish
Manish

Reputation: 111

'flutter' command is not working in Root Directory of Project. [Windows]

I am able to run 'flutter' commands at "C:\Users\pc\AppData\Local\Android\flutter\bin" path. But while trying to generate APK, if i change the path to Project Root Directory, 'flutter' command doesn't work.

I have added all the paths to Environment Variable as mentioned in various other asked questions, including:

C:\Users\pc\AppData\Local\Android\flutter\bin
C:\Program Files\Android\Android Studio\jre\bin\java
C:\Program Files\Git\bin

The 'flutter' command is working fine if i change the path of terminal in Android Studio to "C:\Users\pc\AppData\Local\Android\flutter\bin". I am able to run commands like 'flutter -doctor'.

But while i'm trying to generate apk for release using 'flutter build apk', i'm using the default path set in the terminal i.e. the root directory of the project. It says:

'flutter' is not recognized as an internal or external command, operable program or batch file.

If i try to run the same command in "C:\Users\pc\AppData\Local\Android\flutter\bin", the output is:

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.

It'd be really helpful, if anyone can suggest me something to make it work.

Upvotes: 7

Views: 19429

Answers (3)

Glup3
Glup3

Reputation: 152

You need to update your PATH variable to be able to use the flutter command everywhere.

It should work after you restart your computer. I hope it solved your problem :)

Yours Glup3

Upvotes: 0

Manish
Manish

Reputation: 111

I'm still unable to run commands like 'flutter run' or 'flutter build apk' through the terminal inside Android Studio at my Project Root Directory.

However, these same commands run perfectly well while running in the flutter_console.bat located in the flutter sdk folder. So using the flutter_console.bat , i just change the path to Project Root Directory and generate the apk using 'flutter build apk --release' command.

Upvotes: 4

riftninja
riftninja

Reputation: 1709

First you need to be sure that all the environmental variables are valid/correct, you may need to restart terminal (cmd or your PC) for the changes to take effect.

If that doesn't work you can try setting PATH in cmd/terminal. This usually resets the PATH in cmd (not the Environmental Variables) to the new variable specified, to avoid this use:

set path=%PATH%;C:\Program Files\Git\bin;C:\...

The above command appends the specified path to the already existing PATH rather than overwriting it.

Hope this helps

Upvotes: 2

Related Questions