我在我的Mac系统上安装了Android SDK和Eclipse。我能够使用Eclipse编程,并且已经创建了一些示例应用程序。但是我仍然无法通过终端窗口访问adb。我在终端上尝试了以下命令:
$ pwd
/Users/espireinfolabs/Desktop/soft/android-sdk-mac_x86/platform-tools
$ ls
NOTICE.txt dexdump llvm-rs-cc-2
aapt dx llvm-rs-cc.txt
adb lib source.properties
aidl llvm-rs-cc
$ adb --help
-bash: adb: command not found
我还添加了ls输出,以便您知道我在哪个窗口。
问题是:adb不在您的PATH中。这是shell查找可执行文件的地方。你可以用echo $PATH检查你当前的路径。
Bash将首先尝试在Path中查找名为adb的二进制文件,而不是在当前目录中。因此,如果您当前在platform-tools目录中,只需调用
./adb --help
圆点是您的当前目录,它告诉Bash从那里使用adb。
但实际上,你应该在PATH中添加平台工具,以及Android SDK附带的其他一些工具。你可以这样做:
Find out where you installed the Android SDK. This might be (where $HOME is your user's home directory) one of the following (or verify via Configure > SDK Manager in the Android Studio startup screen):
Linux: $HOME/Android/Sdk
macOS: $HOME/Library/Android/sdk
Find out which shell profile to edit, depending on which file is used:
Linux: typically $HOME/.bashrc
macOS: typically $HOME/.bash_profile
With Zsh: $HOME/.zshrc
Open the shell profile from step two, and at the bottom of the file, add the following lines. Make sure to replace the path with the one where you installed platform-tools if it differs:
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
Save the profile file, then, re-start the terminal or run source ~/.bashrc (or whatever you just modified).
注意,某些第三方框架需要设置ANDROID_HOME,所以添加它也无妨。