有人能发布一个通过终端设置ANDROID_HOME的工作解决方案吗?
我到Android-SDK的路径是/Applications/ADT/sdk。
有人能发布一个通过终端设置ANDROID_HOME的工作解决方案吗?
我到Android-SDK的路径是/Applications/ADT/sdk。
当前回答
在我的.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
在Mac OS X上设置ANDROID_HOME, JAVA_HOME环境变量
在.bash_profile文件中添加
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
为测试
echo $ANDROID_HOME
echo $JAVA_HOME
Android-SDK安装在哪里取决于您如何安装它。
如果你通过他们的网站下载了SDK,然后将应用程序拖放到你的应用程序文件夹中,它很可能在这里: /Applications/ADT/sdk(在你的情况下)。 如果你使用Homebrew (brew cask install android-sdk)安装了SDK,那么它位于这里: /usr/local/Caskroom/android-sdk / {YOUR_SDK_VERSION_NUMBER} 如果SDK是作为Android Studio的一部分自动安装的,那么它位于这里: /用户/ {YOUR_USER_NAME} /图书馆/ Android sdk
一旦你知道了位置,打开一个终端窗口并输入以下内容(将SDK的路径更改为你安装它的方式):
export ANDROID_HOME={YOUR_PATH}
一旦你有了这个集合,你需要把它添加到PATH环境变量:
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
最后,通过重新获取.bash_profile来应用这些更改:
源~ / . bash_profile
输入- echo $ANDROID_HOME检查home是否设置。
echo $ ANDROID_HOME
我有MAC OS X(Sierra) 10.12.2。
我按照以下步骤设置ANDROID_HOME在React Native(Android应用程序)上工作。
打开终端(按命令+空格键,输入终端,按ENTER键)。 向~/.bash_profile添加以下3行。 出口ANDROID_HOME = $ HOME /图书馆/ Android / sdk / 导出路径= $路径:$ ANDROID_HOME /工具 导出路径= $路径:$ ANDROID_HOME /平台工具 最后执行以下命令(或重新启动系统以反映所做的更改)。 源~ / . bash_profile
就是这样。
请注意,如果您将使用~/。Bash_profile,那么它将不会编辑用户的bash配置文件,而是全局的。相反,进入你的用户目录(/ users /username)并直接编辑它:
vim .bash_profile
并插入以下两行关于您的用户名和SDK目录
export PATH=$PATH:/Users/<username>/Library/Android/sdk/tools
export PATH=$PATH:/Users/<username>/Library/Android/sdk/platform-tools