简体   繁体   中英

android' is not recognized as an internal or external command

I'm trying to get the new GCM service to work for me, so I've been following the demo as described here: http://developer.android.com/guide/google/gcm/demo.html

So far, everything works well. However, I'm supposed to build the ant files using the command line now, and that's where things stop working.

For some reason, this command $ android update project --name GCMDemo -p . --target android-16 $ android update project --name GCMDemo -p . --target android-16 gives me a very nice

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

Normally this can be fixed easily with a quick Google search, but I haven't found a single other user with this problem. Could someone tell me what the problem is? My educated guess is that I need to add the Android tools folder to my PATH , but I'd rather be sure first.

Your guess is correct, just add the folder containing android.bat(tools folder) to the PATH. Otherwise the system will not be able to find the program.

Other possibility is change directory (using cd) to the tools folder, and execute the command from there. Since the current directory (whatever it is) is usually in the PATH, the system will find it. But this is not handy, because you frequently want to execute this command being in a different directory.

Find android.bat on your system. On mine (win 8 x64) it's under C:\\Users\\{username}\\AppData\\Local\\Android\\sdk\\tools\\android.bat

Open a command console, and use the 'doskey' command:

doskey android=C:\Users\{username}\AppData\Local\Android\sdk\tools\android.bat $*

This will continue to work in the open command console. To make it permanent is more difficult: http://darkforge.blogspot.com/2010/08/permanent-windows-command-line-aliases.html

You can also try adding it to your PATH as another poster suggested, but that didn't work for me. I recommend an easy gui for doing it, such as https://patheditor2.codeplex.com/

In Windows 7, navigate to

Control Panel\\System and Security\\System > advance system settings > environment variables

and update the path to include the following:

<android-root>\android-sdk-windows\tools

Use semicolons to separate paths if more than one exist.

On Windows 10, add both:

C:\Users\Parag Jain\AppData\Local\Android\sdk\tools
C:\Users\Parag Jain\AppData\Local\Android\sdk\build-tools 

to the PATH environment variable of System and User. Make sure that you close your command prompt and restart a new prompt and then try the command.

图片

Compiling previous answers I did the following to get Android SDK and gradle working (You need gradle working anyway to compile your Android project):

  1. Prerequisites. You have Java jdk, Android SDK and gradle installed in the folders like I found on my computer. Please, check it:

     C:\\Program Files\\Java\\jdk1.X.X_XX\\ C:\\Users{username}\\AppData\\Local\\Android\\sdk\\ C:\\Program Files\\Android\\Android Studio\\gradle\\gradle-XX\\ 
  2. Set up three new system variable (Control Panel\\System and Security\\System Advance system ->settings->environment variables-system variables). Do not forget to change java and gradle versions.

     JAVA_HOME C:\\Program Files\\Java\\jdk1.X.X_XX ANDROID_HOME C:\\Users\\{username}\\AppData\\Local\\Android\\sdk GRADLE_HOME C:\\Program Files\\Android\\Android Studio\\gradle\\gradle-XX\\ 
  3. Add the following paths to system paths (Control Panel\\System and Security\\System Advance system ->settings->environment variables-system variables):

     %JAVA_HOME% %ANDROID_HOME%\\tools\\ %ANDROID_HOME%\\platform-tools %GRADLE_HOME%\\bin 
  4. Close and open once again your Dos application (Cmd terminal, etc.). You might want to REBOOT your computer, to make sure, that the system sees the variables. If you do not want to reboot, you can use the advice of @wordsforthewise

     doskey android=C:\\Users\\{username}\\AppData\\Local\\Android\\sdk\\tools\\android.bat $* 
  5. Check if Android SDK and gradle work properly with the terminal commands

     $ java -version $ android list target $ gradle -v 

What worked for me: Setting up the ANDROID_HOME variable as a System variable instead of a user variable.

I am using Windows 10, not sure if that matters.

I resolved this issue permanently using the below steps.

OS version : windows 7 64 bit Solution : Set environment variable for android sdk and gradle

Step 1: Create new "ANDROID_HOME" User Variable Variable Name: ANDROID_HOME Variable Value C:\\Users{user_name}\\AppData\\Local\\Android\\sdk\\

Step 2: Create new "GRADLE_HOME" User Variable Variable Name: GRADLE_HOME Variable Value C:\\Program Files\\Android\\Android Studio\\gradle\\gradle-xx\\ *Do not forget to change and gradle versions.

Step 3: Create "ANDROID_HOME" System Variable Variable Name: ANDROID_HOME Variable Value C:\\Users{user_name}\\AppData\\Local\\Android\\sdk\\

Step 4: Create new "GRADLE_HOME" System Variable Variable Name: GRADLE_HOME Variable Value C:\\Program Files\\Android\\Android Studio\\gradle\\gradle-xx\\ *Do not forget to change and gradle versions.

Reopen the command prompt and confirm below command output : 1. gradle -v 2. android list target

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM