可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have installed Android SDK and Eclipse on my Mac system. I am able to program using Eclipse and have created few sample applications. But I am still not able to access adb
through the terminal window. I have tried following command in terminal:
$ 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
I have also added the ls
output so that you know in which window I am.
回答1:
adb
is not in your PATH
. This is where the shell looks for executables. You can check your current PATH
with echo $PATH
.
Bash will first try to look for a binary called adb
in your Path, and not in the current directory. Therefore, if you are currently in the platform-tools
directory, just call
./adb --help
The dot is your current directory, and this tells Bash to use adb
from there.
Otherwise, you should add platform-tools
to your PATH
, by adding the path in your shell profile, depending on which file is used:
- Linux: typically
~/.bashrc
- OS X / macOS: typically
~/.profile
or ~/.bash_profile
Add the following line there and replace the path with the one where you installed platform-tools
:
export PATH=/Users/espireinfolabs/Desktop/soft/android-sdk-mac_x86/platform-tools:$PATH
Save the profile file, then, re-start the Terminal or run source ~/.bashrc
(or whatever you just modified).
If you've installed the platform tools somewhere else, change the path accordingly. For Android Studio on OS X, for example, you'd use the following—note the double-quotes that prevent a possible space from breaking the path syntax:
export PATH="/Users/myuser/Library/Android/sdk/platform-tools":$PATH
回答2:
In addition to slhck, this is what worked for me (mac).
To check where your sdk is located.
- Open Android studio and go to:
File -> Project Structure -> Sdk location
Copy the path.
Create the hidden .bash_profile
in your home.
- (open it with
vim
, or open -e
) with the following:
export PATH=/Users/<Your session name>/Library/Android/sdk/platform-tools:/Users/<Your session name>/Library/Android/sdk/tools:$PATH
- Then simply use this in your terminal:
. ~/.bash_profile
SO post on how to find adb devices
回答3:
Quick Answer
Pasting this command in terminal solves the issue in most cases:
** For Current Terminal Session:
- (in macOS) export PATH="~/Library/Android/sdk/platform-tools":$PATH
- (in Windows) i will update asap
** Permanently:
- (in macOS) edit the
~/.bash_profile
using vi ~/.bash_profile
and add this line to it: export PATH="~/Library/Android/sdk/platform-tools":$PATH
However, if not, continue reading.
Detailed Answer
Android Debug Bridge, or adb for short, is usually located in Platform Tools and comes with
Android SDK, You simply need to add its location to system path. So system knows about it, and can use it if necessary.
Find ADB's Location
Path to this folder varies by installation scenario, but common ones are:
- If you have installed Android Studio, path to ADB would be: (Most Common)
- (in macOS) ~/Library/Android/sdk/platform-tools
- (in Windows) i will update asap
- However Android SDK could be Installed without Android studio, in this case your path might be different, and depends on your installation.
Add it to System Path
When you have determined ADB's location, add it to system, follow this syntax and type it in terminal:
回答4:
I don't know how did you install the android SDK. But in Mac OS, what really worked for me is to reinstall it using brew. All problems solved in a row.
brew cask install android-sdk
Later on:
android update sdk --no-ui --filter 'platform-tools'
Like a charm
回答5:
For zsh
users add alias adb='/Users/<yourUserName>/Library/Android/sdk/platform-tools/adb'
to .zshrc
回答6:
For me, I ran into this issue after switching over from bash to zsh so I could get my console to look all awesome fantastic-ish with Hyper and the snazzy theme. I was trying to run my react-native application using react-native run-android
and running into the op's issue. Adding the following into my ~.zshrc
file solved the issue for me:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
回答7:
Simply install adb with brew
brew cask install android-platform-tools
Check if adb is installed
adb devices
回答8:
If you are using zsh
on an OS X, you have to edit the zshrc file.
Use vim or your favorite text editor to open zshrc file:
vim ~/.zshrc
Paste the path to adb
in this file:
export PATH="/Users/{$USER}/Library/Android/sdk/platform-tools":$PATH
回答9:
Or the alternative solution could be
- Make sure you already install for android SDK. Usually it is located under
/Users/your-user-name/Library/Android/sdk
If the SDK is there then run this command. ./platform-tools/adb install your-apk-location
From there you can generate the APK file That's the only sample to check if adb
command is there
回答10:
Start Eclipse via command prompt: like in case of mac -> cd /to_the_dir_where_eclipse
and then open -a Eclipse.app
with super user permissions.
回答11:
It's working fine..
brew install android-sdk
Later on:
android update sdk --no-ui --filter 'platform-tools'