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

我到Android-SDK的路径是/Applications/ADT/sdk。


当前回答

1)开放式基地概况:

open  ~/.bash_profile

2)在基本剖面中添加以下线条:

export PATH=${PATH}:/Users/<username>/Library/Android/sdk/build-tools/27.0.3

保存并关闭基本配置文件。

对我来说27.0.3工作得很好。

其他回答

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

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

把爱传递给下一个懒惰或时间紧张的人。

我想偷懒,在这里找一个Bash脚本;没有。所以我决定是时候学习了,现在就在这里。

#! /bin/bash

# This script will download the Android command line toools to a path of your choosing.
#
# Syntax  : <cmd> <zip> <path>
#
# Example : run with ./get-cli.sh commandlinetools-mac-8512546_latest.zip /usr/local/android
#
# For the latest .zip matching your system visi:
#
#   https://developer.android.com/studio#command-tools 
#
# Note: supplying no args will default to the example
# 
# Respectfully,
#   -Tricknology
#

# command-line-tools zip
cmd_line_tools=$1

# directory to add it to 
android_home_dir=$2

# use defaults if none specified
if [[ cmd_line_tools=="" ]]; then
    #default to aarch64
    cmd_line_tools='commandlinetools-mac-8512546_latest.zip'
fi

if [[ android_home_dir=="" ]]; then
    #statements
    android_home_dir='/usr/local/android'
fi

url=https://dl.google.com/android/repository/"$cmd_line_tools"

###############  gist #########################
# create dir /usr/local/android
# sudo mkdir /usr/local/android

## move tools to usr/local/
# sudo mv cmdline-tools /usr/local/android/sdk

## Set environment variables for Android SDK
# export ANDROID_SDK_ROOT=/usr/local/android/sdk
# export ANDROID_HOME=$ANDROID_SDK_ROOT

## Insert executable file paths in PATH
# export PATH=$PATH:$ANDROID_HOME/bin
# export PATH=$PATH:$ANDROID_HOME/tools
# export PATH=$PATH:$ANDROID_HOME/tools/bin
# export PATH=$PATH:$ANDROID_HOME/platform-tools
################ end gist #######################

# Create directory 
# going to ask for password to create this
echo
echo "-----------------------------------------------------"
echo creating directories
echo "-----------------------------------------------------"
echo
    [[ -f "$cmd_line_tools" ]] && { 
        echo creatig dir:  $android_home_dir; 
            sudo mkdir $android_home_dir;
        } || echo $android_home_dir exists;
echo
echo "-----------------------------------------------------"
echo downloading from: $url
echo               to: $android_home_dir
echo "-----------------------------------------------------"
     curl $url --output $cmd_line_tools
echo 
echo done
echo unzipping       : $cmd_line_tools
    unzip $cmd_line_tools
echo done
echo 
echo moving to       : "$android_home_dir"/sdk

    [ -d "$android_home_dir"/sdk ] &&
    {   echo "$android_home_dir"/sdk already exists!;
        echo cleaning up : $cmd_line_tools;
            sudo rm $cmd_line_tools;
        echo cleaning up : cmdline-tools;
            sudo rm -rf "cmdline-tools";
        echo exiting!;
        exit -1;
    };
    sudo mv cmdline-tools "$android_home_dir"/sdk
echo
echo done
echo "-----------------------------------------------------"
echo " Setting Environment Variables (Global)"
echo "-----------------------------------------------------"
echo
    echo setting ANDROID_SDK_ROOT=$android_home_dir/sdk
        export ANDROID_SDK_ROOT=$android_home_dir/sdk
        echo $(export ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT)
    echo setting ANDROID_HOME=$ANDROID_SDK_ROOT
        export ANDROID_HOME=$ANDROID_SDK_ROOT
        echo $(export ANDROID_HOME=$ANDROID_HOME)
echo
echo "-----------------------------------------------------"
echo current path: $PATH
echo "-----------------------------------------------------"
echo
    ah_bin=$ANDROID_HOME/bin
    ah_tools=$ANDROID_HOME/tools
    ah_tools_bin=$ANDROID_HOME/tools/bin
    ah_plat_tools=$ANDROID_HOME/platform-tools
    [ $(grep -q "$PATH" $ah_bin) ]         && echo $ah_bin exists          || export PATH=$PATH:$ah_bin
echo $PATH
echo
    [ $(grep -q "$PATH" $ah_tools) ]       && echo $ah_tools exists        || export PATH=$PATH:$ah_tools
echo $PATH
echo
    [ $(grep -q "$PATH" $ah_tools_bin) ]   && echo $ah_tools_bin exists    || export PATH=$PATH:$ah_tools_bin
echo $PATH
echo
    [ $(grep -q "$PATH" $ah_plat_tools) ]  && echo $ah_plat_tools exists   || export PATH=$PATH:$ah_plat_tools
echo $PATH
echo
echo "-----------------------------------------------------"
echo setting path to  : $PATH
echo "-----------------------------------------------------"
echo
     export PATH=$PATH
echo done
echo 
echo "-----------------------------------------------------"
echo cleaning up 
echo "-----------------------------------------------------"
echo
echo removing $cmd_line_tools
     sudo rm $cmd_line_tools
echo done
echo
echo removing "cmdline-tools"
     sudo rm -rf "cmdline-tools"
echo done
echo
echo "-----------------------------------------------------"
echo
echo finished!
echo let ne show you the PATH $(echo $PATH) 
3cho
3cho congratulations on your new ANDROID_HOME=$(echo $ANDROID_HOME)
exit 0
EOF

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

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

如果你安装了自制软件,

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

检查该路径是否存在:

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

export ANDROID_HOME=~/Library/Android/sdk

最后将其添加到path:

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

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

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

ANDROID_HOME环境与ANDROID_SDK_ROOT环境相同,这意味着它定义了SDK安装目录的路径。

点击这里了解更多。

我设置了独立于Android studio的Android SDK,这让我能够更好地控制内容的位置。

首先,我从官方网站下载了Android SDK(命令行工具)。

cd $HOME/Downloads
curl https://dl.google.com/android/repository/commandlinetools-mac-7302050_latest.zip --output android-sdk.zip

其次,我解压缩下载目录中的文件,这个过程将生成一个名为cmdline-tools的目录。

unzip android-sdk.zip

第三,在本地目录中创建一个名为android的目录。 (/usr/local系统范围,由本地管理员(通常是您)安装的只读文件)

sudo mkdir /usr/local/android

第四,我将解压生成的目录移动到android目录,将其重命名为sdk。(将来我会在sdk旁边添加ndk目录)

sudo mv cmdline-tools /usr/local/android/sdk

第五,我手动将环境变量添加到我个人目录中的.zshrc文件中。

nano $HOME/.zshrc
# ...

# Set environment variables for Android SDK
export ANDROID_SDK_ROOT=/usr/local/android/sdk
export ANDROID_HOME=$ANDROID_SDK_ROOT

# Insert executable file paths in PATH environment variable
export PATH=$PATH:$ANDROID_HOME/bin
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

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

ANDROID_HOME通常是一个类似于.android的目录。它是存储Debug Key之类的东西的地方。

export ANDROID_HOME=~/.android 

您可以为您的登录自动化它。只需将它添加到你的.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"

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

修改~/后。Bash_profile,然后执行以下操作(或注销并返回):

source ~/.bash_profile