在Mac OS X上设置ANDROID_HOME环境变量

时间:2022-12-04 23:11:54

Could anybody post a working solution for setting ANDROID_HOME via the terminal?

有人能通过终端发布一个安装ANDROID_HOME的工作解决方案吗?

My path to the Android-SDK is /Applications/ADT/sdk.

我的Android-SDK的路径是/应用/ADT/sdk。

8 个解决方案

#1


401  

Where the Android-SDK is installed depends on how you installed it.

Android-SDK的安装位置取决于您如何安装它。

  1. If you downloaded the SDK through their website and then dragged/dropped the Application to your Applications folder, it's most likely here:

    如果您通过他们的网站下载SDK,然后将应用程序拖放到您的应用程序文件夹中,最可能的情况是:

    /Applications/ADT/sdk (as it is in your case).

    /应用程序/ADT/sdk(如您的情况)。

  2. If you installed the SDK using Homebrew (brew cask install android-sdk), then it's located here:

    如果你使用Homebrew安装SDK (brew cask安装android-sdk),那么它就位于这里:

    /usr/local/Caskroom/android-sdk/{YOUR_SDK_VERSION_NUMBER}

    /usr/local/Caskroom/android-sdk / { YOUR_SDK_VERSION_NUMBER }

  3. If the SDK was installed automatically as part of Android Studio then it's located here:

    如果SDK是作为Android Studio的一部分自动安装的,那么它就位于这里:

    /Users/{YOUR_USER_NAME}/Library/Android/sdk

    /用户/ { YOUR_USER_NAME } /图书馆/ Android sdk

Once you know the location, open a terminal window and enter the following (changing out the path to the SDK to be however you installed it):

一旦您知道了位置,打开一个终端窗口,输入以下内容(将SDK的路径更改为安装方式):

export ANDROID_HOME={YOUR_PATH}

Once you have this set, you need to add this to the PATH environment variable:

一旦您有了这个集合,您需要将它添加到PATH环境变量:

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Lastly apply these changes by re-sourcing .bash_profile:

最后通过资源资源。bash_profile应用这些更改:

source ~/.bash_profile

源~ / . bash_profile

#2


147  

In Terminal:

在终端:

nano ~/.bash_profile 

Add lines:

添加行:

export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

Check it worked:

检查工作:

source ~/.bash_profile
echo $ANDROID_HOME

#3


37  

Adding the following to my .bash_profile worked for me:

在我的.bash_profile中添加以下内容对我是有效的:

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

#4


32  

quoting @user2993582's answer

引用@user2993582的回答

export PATH=$PATH:$ANDROID_HOME/bin

The 'bin' part has changed and it should be

“箱子”部分已经改变了,应该改变了

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

#5


9  

Could anybody post a working solution for doing this in the terminal?

有人能在终端上发布一个解决方案吗?

ANDROID_HOME is usually a directory like .android. Its where things like the Debug Key will be stored.

ANDROID_HOME通常是一个像.android这样的目录。它将存储诸如调试键之类的东西。

export ANDROID_HOME=~/.android 

You can automate it for your login. Just add it to your .bash_profile (below is from my OS X 10.8.5 machine):

您可以自动为您的登录。将它添加到.bash_profile(下面是我的OS X 10.8.5机器):

$ cat ~/.bash_profile
# MacPorts Installer addition on 2012-07-19 at 20:21:05
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

# Android
export ANDROID_NDK_ROOT=/opt/android-ndk-r9
export ANDROID_SDK_ROOT=/opt/android-sdk
export JAVA_HOME=`/usr/libexec/java_home`
export ANDROID_HOME=~/.android

export PATH="$ANDROID_SDK_ROOT/tools/":"$ANDROID_SDK_ROOT/platform-tools/":"$PATH"

According to David Turner on the NDK Mailing List, both ANDROID_NDK_ROOT and ANDROID_SDK_ROOT need to be set because other tools depend on those values (see Recommended NDK Directory?).

根据NDK邮件列表上的David Turner,需要设置ANDROID_NDK_ROOT和ANDROID_SDK_ROOT,因为其他工具依赖于这些值(参见推荐的NDK目录?)

After modifying ~/.bash_profile, then perform the following (or logoff and back on):

后修改~ /。bash_profile,然后执行以下操作(或退出并返回):

source ~/.bash_profile

#6


9  

To set ANDROID_HOME, variable, you need to know how you installed android dev setup.

要设置ANDROID_HOME变量,您需要知道如何安装android开发设置。

If you don't know you can check if the following paths exist in your machine. Add the following to .bashrc, .zshrc, or .profile depending on what you use

如果您不知道,您可以检查以下路径是否存在于您的计算机中。根据使用的不同,向.bashrc、.zshrc或.profile添加以下内容

If you installed with homebrew,

如果你安装了homebrew,

export ANDROID_HOME=/usr/local/opt/android-sdk

Check if this path exists:

检查该路径是否存在:

If you installed android studio following the website,

如果你在网站后面安装了android studio,

export ANDROID_HOME=~/Library/Android/sdk

Finally add it to path:

最后添加到path:

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

If you're too lazy to open an editor do this:

如果你懒得打开编辑器,可以这样做:

echo "export ANDROID_HOME=~/Library/Android/sdk" >> ~/.bashrc
echo "export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools" >> ~/.bashrc

#7


9  

I am having MAC OS X(Sierra) 10.12.2.

我有MAC OS X(Sierra) 10.12.2。

I set ANDROID_HOME to work on React Native(for Android apps) by following the following steps.

通过以下步骤,我将ANDROID_HOME设置为在React Native上运行。

  • Opened Terminal (press Command+R, type Terminal, Hit ENTER).
  • 打开终端(按命令+R,输入终端,按回车)。
  • Added the following 4 lines to ~/.bash_profile.

    向~/.bash_profile添加以下4行。

    export ANDROID_HOME=/Users/$USER/Library/Android/sdk/
    export PATH=$PATH:$ANDROID_HOME
    export PATH=$PATH:$ANDROID_HOME/tools
    export PATH=$PATH:$ANDROID_HOME/platform-tools
    
  • Finally execute the below command (or RESTART the system to reflect the changes made).

    最后执行下面的命令(或重新启动系统以反映所做的更改)。

    source ~/.bash_profile

    源~ / . bash_profile

That's it.

就是这样。

#8


4  

People, note that if you will use ~/.bash_profile then it will edit not your user's bash profile, but global. Instead go to your users directory (/Users/username) and edit it directly:

人们注意到,如果你使用~/。然后它将编辑不是您的用户的bash配置文件,而是全局的。而是进入你的用户目录(/用户/用户名)并直接编辑它:

vim .bash_profile

And insert following two lines with respect to your Username and SDK directory

并插入以下两行关于您的用户名和SDK目录。

export PATH=$PATH:/Users/<username>/Library/Android/sdk/tools
export PATH=$PATH:/Users/<username>/Library/Android/sdk/platform-tools

#1


401  

Where the Android-SDK is installed depends on how you installed it.

Android-SDK的安装位置取决于您如何安装它。

  1. If you downloaded the SDK through their website and then dragged/dropped the Application to your Applications folder, it's most likely here:

    如果您通过他们的网站下载SDK,然后将应用程序拖放到您的应用程序文件夹中,最可能的情况是:

    /Applications/ADT/sdk (as it is in your case).

    /应用程序/ADT/sdk(如您的情况)。

  2. If you installed the SDK using Homebrew (brew cask install android-sdk), then it's located here:

    如果你使用Homebrew安装SDK (brew cask安装android-sdk),那么它就位于这里:

    /usr/local/Caskroom/android-sdk/{YOUR_SDK_VERSION_NUMBER}

    /usr/local/Caskroom/android-sdk / { YOUR_SDK_VERSION_NUMBER }

  3. If the SDK was installed automatically as part of Android Studio then it's located here:

    如果SDK是作为Android Studio的一部分自动安装的,那么它就位于这里:

    /Users/{YOUR_USER_NAME}/Library/Android/sdk

    /用户/ { YOUR_USER_NAME } /图书馆/ Android sdk

Once you know the location, open a terminal window and enter the following (changing out the path to the SDK to be however you installed it):

一旦您知道了位置,打开一个终端窗口,输入以下内容(将SDK的路径更改为安装方式):

export ANDROID_HOME={YOUR_PATH}

Once you have this set, you need to add this to the PATH environment variable:

一旦您有了这个集合,您需要将它添加到PATH环境变量:

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Lastly apply these changes by re-sourcing .bash_profile:

最后通过资源资源。bash_profile应用这些更改:

source ~/.bash_profile

源~ / . bash_profile

#2


147  

In Terminal:

在终端:

nano ~/.bash_profile 

Add lines:

添加行:

export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

Check it worked:

检查工作:

source ~/.bash_profile
echo $ANDROID_HOME

#3


37  

Adding the following to my .bash_profile worked for me:

在我的.bash_profile中添加以下内容对我是有效的:

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

#4


32  

quoting @user2993582's answer

引用@user2993582的回答

export PATH=$PATH:$ANDROID_HOME/bin

The 'bin' part has changed and it should be

“箱子”部分已经改变了,应该改变了

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

#5


9  

Could anybody post a working solution for doing this in the terminal?

有人能在终端上发布一个解决方案吗?

ANDROID_HOME is usually a directory like .android. Its where things like the Debug Key will be stored.

ANDROID_HOME通常是一个像.android这样的目录。它将存储诸如调试键之类的东西。

export ANDROID_HOME=~/.android 

You can automate it for your login. Just add it to your .bash_profile (below is from my OS X 10.8.5 machine):

您可以自动为您的登录。将它添加到.bash_profile(下面是我的OS X 10.8.5机器):

$ cat ~/.bash_profile
# MacPorts Installer addition on 2012-07-19 at 20:21:05
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

# Android
export ANDROID_NDK_ROOT=/opt/android-ndk-r9
export ANDROID_SDK_ROOT=/opt/android-sdk
export JAVA_HOME=`/usr/libexec/java_home`
export ANDROID_HOME=~/.android

export PATH="$ANDROID_SDK_ROOT/tools/":"$ANDROID_SDK_ROOT/platform-tools/":"$PATH"

According to David Turner on the NDK Mailing List, both ANDROID_NDK_ROOT and ANDROID_SDK_ROOT need to be set because other tools depend on those values (see Recommended NDK Directory?).

根据NDK邮件列表上的David Turner,需要设置ANDROID_NDK_ROOT和ANDROID_SDK_ROOT,因为其他工具依赖于这些值(参见推荐的NDK目录?)

After modifying ~/.bash_profile, then perform the following (or logoff and back on):

后修改~ /。bash_profile,然后执行以下操作(或退出并返回):

source ~/.bash_profile

#6


9  

To set ANDROID_HOME, variable, you need to know how you installed android dev setup.

要设置ANDROID_HOME变量,您需要知道如何安装android开发设置。

If you don't know you can check if the following paths exist in your machine. Add the following to .bashrc, .zshrc, or .profile depending on what you use

如果您不知道,您可以检查以下路径是否存在于您的计算机中。根据使用的不同,向.bashrc、.zshrc或.profile添加以下内容

If you installed with homebrew,

如果你安装了homebrew,

export ANDROID_HOME=/usr/local/opt/android-sdk

Check if this path exists:

检查该路径是否存在:

If you installed android studio following the website,

如果你在网站后面安装了android studio,

export ANDROID_HOME=~/Library/Android/sdk

Finally add it to path:

最后添加到path:

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

If you're too lazy to open an editor do this:

如果你懒得打开编辑器,可以这样做:

echo "export ANDROID_HOME=~/Library/Android/sdk" >> ~/.bashrc
echo "export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools" >> ~/.bashrc

#7


9  

I am having MAC OS X(Sierra) 10.12.2.

我有MAC OS X(Sierra) 10.12.2。

I set ANDROID_HOME to work on React Native(for Android apps) by following the following steps.

通过以下步骤,我将ANDROID_HOME设置为在React Native上运行。

  • Opened Terminal (press Command+R, type Terminal, Hit ENTER).
  • 打开终端(按命令+R,输入终端,按回车)。
  • Added the following 4 lines to ~/.bash_profile.

    向~/.bash_profile添加以下4行。

    export ANDROID_HOME=/Users/$USER/Library/Android/sdk/
    export PATH=$PATH:$ANDROID_HOME
    export PATH=$PATH:$ANDROID_HOME/tools
    export PATH=$PATH:$ANDROID_HOME/platform-tools
    
  • Finally execute the below command (or RESTART the system to reflect the changes made).

    最后执行下面的命令(或重新启动系统以反映所做的更改)。

    source ~/.bash_profile

    源~ / . bash_profile

That's it.

就是这样。

#8


4  

People, note that if you will use ~/.bash_profile then it will edit not your user's bash profile, but global. Instead go to your users directory (/Users/username) and edit it directly:

人们注意到,如果你使用~/。然后它将编辑不是您的用户的bash配置文件,而是全局的。而是进入你的用户目录(/用户/用户名)并直接编辑它:

vim .bash_profile

And insert following two lines with respect to your Username and SDK directory

并插入以下两行关于您的用户名和SDK目录。

export PATH=$PATH:/Users/<username>/Library/Android/sdk/tools
export PATH=$PATH:/Users/<username>/Library/Android/sdk/platform-tools