android' is not recognized as an internal or e

2020-01-28 08:20发布

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 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.

7条回答
霸刀☆藐视天下
2楼-- · 2020-01-28 08:59

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-X.X\
    
  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-X.X\
    
  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
    
查看更多
Summer. ? 凉城
3楼-- · 2020-01-28 09:01

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.

查看更多
▲ chillily
4楼-- · 2020-01-28 09:10

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.

查看更多
叛逆
5楼-- · 2020-01-28 09:11

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.

image

查看更多
做自己的国王
6楼-- · 2020-01-28 09:23

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/

查看更多
ゆ 、 Hurt°
7楼-- · 2020-01-28 09:23

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.

查看更多
登录 后发表回答