简体   繁体   English

-bash: android: 在 Mac OSX 上找不到命令

[英]-bash: android: command not found on Mac OSX

I've been diving into Android development for a while, and now I want to use some project (helpshift) in my app.我已经潜入 Android 开发一段时间了,现在我想在我的应用程序中使用一些项目 (helpshift)。 On the website they have some example apps in which the readme says: Run the following inside the /HelpshiftDemo folder.在网站上,他们有一些示例应用程序,其中自述文件说:在 /HelpshiftDemo 文件夹中运行以下内容。

android update project -t android-17 -p .

So I do this, but unfortunately this gives me an error saying -bash: android: command not found .所以我这样做了,但不幸的是这给了我一个错误,说-bash: android: command not found I understand this, because "android" as such doesn't refer to anything on my laptop (Mac OSX).我理解这一点,因为“android”本身并不指代我的笔记本电脑(Mac OSX)上的任何东西。 So I thought it is maybe referring to the adb.所以我认为它可能是指adb。 So I tried replacing android for the direct path to my adb:所以我尝试将android替换为我的 adb 的直接路径:

/Users/kramer65/dev/adt-bundle-mac-x86_64-20130917/sdk/platform-tools/adb update project -t android-17 -p .

This gives me a humongous output with more information on adb, which is I guess not the expected result.这给了我一个关于 adb 的更多信息的巨大输出,我想这不是预期的结果。

So my questions;所以我的问题; what does android refer to, and how can I fix this on Mac OSX? android指的是什么,我该如何在 Mac OSX 上解决这个问题?

The android tool is located in the tools directory in your SDK. android工具位于 SDK 的tools目录中。 You need to add this to your PATH environment variable so that bash can recognize it.您需要将此添加到您的PATH环境变量中,以便 bash 可以识别它。

You can do this by adding it to your PATH in your .bash_profile file.您可以通过将其添加到.bash_profile文件中的PATH来实现。 This file should be located in your home directory.此文件应位于您的主目录中。 Create if it doesn't exist using vi .bash_profile and add the following line to it:如果它不存在,则使用vi .bash_profile创建,并向其添加以下行:

export PATH=<path_to_android_sdk>/platform-tools:<path_to_android_sdk>/tools:$PATH

where <path_to_android_sdk> is to be replaced with the path to your SDK.其中<path_to_android_sdk>将替换为您的 SDK 的路径。 For example: "/Users/me/android-sdk-mac_86/platform-tools"例如: "/Users/me/android-sdk-mac_86/platform-tools"

Step 0步骤 0

The first step is install Android SDK: https://developer.android.com/studio第一步是安装Android SDK: https : //developer.android.com/studio

I don't like the default configurations.我不喜欢默认配置。 I installed SDK in this folder:我在这个文件夹中安装了 SDK:

/Users/<Username>/Android\ SDK

ℹ️ The default path is ℹ️ 默认路径是

$HOME/Library/Android/sdk

Step 1步骤1

The next command open your bash or zshrc configuration file:下一个命令打开你的 bash 或 zshrc 配置文件:

Bash profile:巴什简介:

vim ~/.bash_profile

If you use zsh:如果您使用 zsh:

vim ~/.zshrc

Step 2第2步

You're ready to update your configurations:您已准备好更新您的配置:

# File: .bash_profile | .zshrc

# Custom path to Android SDK folder. 
# If you use the default configuration please change ANDROID_HOME to $HOME/Library/Android/sdk
export ANDROID_HOME=/Users/<Username>/Android\ SDK
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

Step 3第 3 步

Option 1: Restart your terminal and you should be able to use android command选项 1:重新启动您的终端,您应该可以使用android命令

Option 2: source your bash or zsh profile.选项 2:获取您的bashzsh配置文件。

Example: source ~/.bash_profile / source ~/.zshrc示例: source ~/.bash_profile / source ~/.zshrc

I spent so much time trying to figure out, this steps helped me ( from http://docs.phonegap.com/en/2.2.0/guide_getting-started_android_index.md.html ) You need to execute your .bash_profile to update your PATH .我花了很多时间试图弄清楚,这些步骤帮助了我(来自http://docs.phonegap.com/en/2.2.0/guide_getting-started_android_index.md.html )你需要执行你的.bash_profile来更新你的PATH

Set up your PATH environment variable on Mac OS在 Mac OS 上设置 PATH 环境变量

Open the Terminal program (this is in your Applications/Utilites folder by default).打开终端程序(默认情况下位于您的应用程序/实用程序文件夹中)。 Run the following command运行以下命令

touch ~/.bash_profile; open ~/.bash_profile

This will open the file in the your default text editor.这将在您的默认文本编辑器中打开文件。 You need to add the path to your Android SDK platform-tools and tools directory.您需要将路径添加到您的 Android SDK 平台工具和工具目录。 In my example I will use "/Development/android-sdk-macosx" as the directory the SDK is installed in. Add the following line:在我的示例中,我将使用“/Development/android-sdk-macosx”作为安装 SDK 的目录。添加以下行:

export PATH=${PATH}:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools

Save the file and quit the text editor.保存文件并退出文本编辑器。 Execute your .bash_profile to update your PATH:执行您的.bash_profile以更新您的 PATH:

source ~/.bash_profile

Now every time you open the Terminal program you PATH will included the Android SDK.现在,每次打开终端程序时, PATH都会包含 Android SDK。

Problem Solved For Android Studio Users:为 Android Studio 用户解决的问题:

I am using Mac OS X Elcapitan version 10.11.X.我使用的是 Mac OS X Elcapitan 版本 10.11.X。

Under my home directory I found .bash_profile.save file.在我的主目录下,我找到了.bash_profile.save文件。 I opened that file using sublime (you can use any other editor).我使用 sublime 打开该文件(您可以使用任何其他编辑器)。 Then I added this line然后我添加了这一行

export PATH=${PATH}:/Users/UserName/Library/Android/sdk/platform-tools:/Users/UserName/Library/Android/sdk/tools

Replace " UserName " with your UserName.用您的用户名替换“用户名”。

open terminal then run打开终端然后运行

 source ~/.bash_profile 

here you go.干得好。

First add these lines to your ~/.bashrc file:首先将这些行添加到您的 ~/.bashrc 文件中:

export ANDROID_HOME=${HOME}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

then:然后:

source ~/.bashrc
export PATH="/Users/me/Library/Android/sdk/platform-tools/":"/Users/me/Library/Android/sdk/tools/":$PATH

为我工作

Add the following lines into ~/.bash_profile and source ~/.bash_profile将以下行添加到 ~/.bash_profile 和 source ~/.bash_profile

export ANDROID_HOME=/Users/macbook/Library/Android/sdk/
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

This is working for me这对我有用

Update the path.更新路径。

Open the Terminal program from Spotlight.从 Spotlight 打开终端程序。 Run the following command:运行以下命令:

touch ~/.bash_profile; open ~/.bash_profile

Then save following code然后保存以下代码

export PATH=${PATH}:/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools

For my case, path is就我而言,路径是

export PATH=/Users/<user-name>/Development/android-sdk-macosx/platform-tools:/Users/<user-name>/Development/android-sdk-macosx/tools:$PATH 

Save the file and quit the text editor.保存文件并退出文本编辑器。 Execute your .bash_profile to update your PATH:执行您的 .bash_profile 以更新您的 PATH:

source ~/.bash_profile

Then run adb.然后运行adb。

This is the issue because of you didn't give proper android sdk path variable in .bash_profile.这是问题所在,因为您没有在 .bash_profile 中提供正确的 android sdk 路径变量。 for this you must follow the below steps.为此,您必须遵循以下步骤。
1. Check android sdk path: for this you should open android studio->preferences and click on Android SDK in newly open window in that look for Android SDK location textfield in that you can find path of Android SDK. 1. 检查 android sdk 路径:为此您应该打开 android studio->preferences 并在新打开的窗口中单击 Android SDK,在该窗口中查找 Android SDK 位置文本字段,您可以在其中找到 Android SDK 的路径。 For me it shows like: /Users/<your_name>/Library/Android/sdk .对我来说,它显示为: /Users/<your_name>/Library/Android/sdk here <your_name> is name of your home directory.这里<your_name>是您的主目录的名称。
2. Open your terminal enter cd ~ command. 2. 打开你的终端输入cd ~命令。
3. and enter vi .bash_profile . 3. 然后输入vi .bash_profile
4. In vi editor enter following 4.在vi编辑器中输入以下内容
export ANDROID_HOME=/Users/Murali/Library/Android/sdk export PATH=$ANDROID_HOME/tools:$PATH export PATH=$ANDROID_HOME/platform-tools:$PATH
Save it by press esc button and enter :wq .esc按钮保存并输入:wq
5. After this close your terminal and open it again. 5. 在此之后关闭您的终端并再次打开它。 6. To apply all your changes in .bash_profile enter following command 6. 要应用.bash_profile所有更改, .bash_profile输入以下命令
source .bash_profile . source .bash_profile
7. Enter android command. 7. 输入android命令。 Hope this now working fine :-)希望这现在工作正常:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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