android' 不被识别为内部或外部命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11350692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:07:07  来源:igfitidea点击:

android' is not recognized as an internal or external command

androidcommand-line

提问by Sander van't Veer

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

我正在尝试让新的 GCM 服务为我工作,所以我一直在关注这里描述的演示:http: //developer.android.com/guide/google/gcm/demo.html

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

到目前为止,一切正常。但是,我现在应该ant使用命令行构建文件,这就是事情停止工作的地方。

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

出于某种原因,这个命令$ android update project --name GCMDemo -p . --target android-16给了我一个很好的

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

通常,通过快速的 Google 搜索可以轻松解决此问题,但我还没有发现其他用户遇到此问题。有人能告诉我问题是什么吗?我有根据的猜测是我需要将 Android 工具文件夹添加到我的PATH.

回答by Ixx

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.

您的猜测是正确的,只需将包含 android.bat(工具文件夹)的文件夹添加到 PATH。否则系统将无法找到该程序。

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.

另一种可能性是将目录(使用 cd)更改为工具文件夹,然后从那里执行命令。由于当前目录(不管它是什么)通常在 PATH 中,系统会找到它。但这并不方便,因为您经常希望在不同的目录中执行此命令。

回答by wordsforthewise

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

在您的系统上找到 android.bat。在我的 (win 8 x64) 下,它位于 C:\Users\{username}\AppData\Local\Android\sdk\tools\android.bat

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

打开命令控制台,并使用“doskey”命令:

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

这将继续在打开的命令控制台中工作。让它永久更难: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/

您也可以按照另一张海报的建议尝试将其添加到您的 PATH 中,但这对我不起作用。我推荐一个简单的 gui 来做,比如https://patheditor2.codeplex.com/

回答by Piyush

In Windows 7, navigate to

在 Windows 7 中,导航到

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.

如果存在多个路径,请使用分号分隔路径。

回答by Parag Jain

On Windows 10, add both:

在 Windows 10 上,同时添加:

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

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

到系统和用户的PATH环境变量。确保关闭命令提示符并重新启动新的提示符,然后尝试该命令。

image

图片

回答by Roman

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

编译以前的答案我做了以下事情来让 Android SDK 和 gradle 工作(你需要 gradle 工作来编译你的 Android 项目):

  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
    
  1. 先决条件。您在我在计算机上找到的文件夹中安装了 Java jdk、Android SDK 和 gradle。请检查一下:

    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. 设置三个新的系统变量(控制面板\系统和安全\系统高级系统->设置->环境变量-系统变量)。不要忘记更改 java 和 gradle 版本。

    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. 将以下路径添加到系统路径(控制面板\系统和安全\系统高级系统->设置->环境变量-系统变量):

    %JAVA_HOME%
    %ANDROID_HOME%\tools\
    %ANDROID_HOME%\platform-tools
    %GRADLE_HOME%\bin
    
  4. 关闭并再次打开您的 Dos 应用程序(Cmd 终端等)。您可能需要重新启动计算机,以确保系统看到这些变量。如果您不想重新启动,可以使用@wordsforthewise 的建议

    doskey android=C:\Users\{username}\AppData\Local\Android\sdk\tools\android.bat $*
    
  5. 使用终端命令检查 Android SDK 和 gradle 是否正常工作

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

回答by Vaibhav Pawar

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

对我有用的是:将 ANDROID_HOME 变量设置为系统变量而不是用户变量。

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

我使用的是 Windows 10,不确定这是否重要。

回答by praveen kedar

I resolved this issue permanently using the below steps.

我使用以下步骤永久解决了这个问题。

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

操作系统版本:windows 7 64 位解决方案:为 android sdk 和 gradle 设置环境变量

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

第 1 步:创建新的“ANDROID_HOME”用户变量变量名称:ANDROID_HOME 变量值 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-x.x\ *Do not forget to change and gradle versions.

第二步:新建“GRADLE_HOME”用户变量变量名:GRADLE_HOME 变量值 C:\Program Files\Android\Android Studio\gradle\gradle-xx\ *不要忘记更改和gradle版本。

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

第三步:创建“ANDROID_HOME”系统变量变量名:ANDROID_HOME变量值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-x.x\ *Do not forget to change and gradle versions.

第四步:新建“GRADLE_HOME”系统变量变量名:GRADLE_HOME 变量值 C:\Program Files\Android\Android Studio\gradle\gradle-xx\ *不要忘记更改和gradle版本。

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

重新打开命令提示符并确认以下命令输出: 1. gradle -v 2. android list target