无法通过终端访问 OS X 中的 adb,“找不到命令”
我已经在 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 输出,以便您知道我在哪个窗口中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(22)
问题是:
adb
不在您的PATH
中。 这是 shell 查找可执行文件的位置。您可以使用echo $PATH
检查当前的PATH
。Bash 将首先尝试在您的路径中而不是在当前目录中查找名为
adb
的二进制文件。因此,如果您当前位于platform-tools
目录中,只需调用点是您的当前目录,这会告诉 Bash 从那里使用
adb
。但实际上,您应该将
platform-tools
添加到您的PATH
中,以及 Android SDK 附带的一些其他工具。操作方法如下:找出 Android SDK 的安装位置。这可能是(其中
$HOME
是您用户的主目录)以下之一(或通过 Android Studio 启动屏幕中的配置 > SDK 管理器进行验证):$HOME/Android/Sdk
$HOME/Library/Android/sdk
找出要编辑的 shell 配置文件,取决于使用哪个文件:
$HOME/.bashrc
$HOME/.bash_profile
$HOME/.zshrc
打开第二步中的 shell 配置文件,然后在文件底部添加以下行。如果路径不同,请确保将路径替换为安装
platform-tools
的路径:保存配置文件,然后重新启动终端或运行
source ~/. bashrc
(或您刚刚修改的任何内容)。请注意,某些第三方框架需要设置
ANDROID_HOME
,因此添加它并没有什么坏处。The problem is:
adb
is not in yourPATH
. This is where the shell looks for executables. You can check your currentPATH
withecho $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 theplatform-tools
directory, just callThe dot is your current directory, and this tells Bash to use
adb
from there.But actually, you should add
platform-tools
to yourPATH
, as well as some other tools that the Android SDK comes with. This is how you do it: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):$HOME/Android/Sdk
$HOME/Library/Android/sdk
Find out which shell profile to edit, depending on which file is used:
$HOME/.bashrc
$HOME/.bash_profile
$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:Save the profile file, then, re-start the terminal or run
source ~/.bashrc
(or whatever you just modified).Note that setting
ANDROID_HOME
is required for some third party frameworks, so it does not hurt to add it.对于
zsh
用户。将alias adb='/Users/$USER/Library/Android/sdk/platform-tools/adb'
添加到.zshrc
文件中。然后运行
source ~/.zshrc
命令For
zsh
users. Addalias adb='/Users/$USER/Library/Android/sdk/platform-tools/adb'
to.zshrc
file.Then run
source ~/.zshrc
command在终端中运行命令
nano $HOME/.zshrc
必须包含下一行:
按 Ctrl + X 将文件保存在编辑器中,输入 Yes 或 No,然后按 Enter 键
运行
source ~/.zshrc
在终端中检查adb,运行
adb
run command in terminal
nano $HOME/.zshrc
Must include next lines:
Press Ctrl + X to save file in editor,Enter Yes or No and hit Enter key
Run
source ~/.zshrc
Check adb in terminal, run
adb
除了 slhck 之外,这对我(mac)也有用。
检查您的 sdk 所在位置。
复制路径。
在您的家中创建隐藏的
.bash_profile
。vim
或open -e
打开它)并使用以下命令:。 ~/.bash_profile
关于如何查找 adb 设备的帖子
In addition to slhck, this is what worked for me (mac).
To check where your sdk is located.
Copy the path.
Create the hidden
.bash_profile
in your home.vim
, oropen -e
) with the following:. ~/.bash_profile
SO post on how to find adb devices
快速解答
在终端中粘贴此命令可以解决大多数情况下的问题:
** 对于当前终端会话:
** 永久:
~/.bash_profile
使用vi ~/.bash_profile
并将此行添加到其中: export PATH="~/Library/Android/sdk/platform-tools":$PATH但是,如果没有,继续阅读。
详细答案
Android Debug Bridge,简称adb,通常位于Platform Tools中,并附带
Android SDK,您只需将其位置添加到系统路径即可。所以系统知道它,并且可以在必要时使用它。
查找 ADB 的位置
该文件夹的路径因安装场景而异,但常见的是:
如果您已在其他位置安装了 Android Studio,请通过以下方式确定其位置:
将其添加到系统路径
确定 ADB 的位置后,将其添加到系统,遵循以下语法并在终端中键入:
(在 macOS 中)
导出 PATH="your/path/to/adb/here":$PATH
例如:导出 PATH="~/Library/Android/sdk/platform-tools":$PATH
Quick Answer
Pasting this command in terminal solves the issue in most cases:
** For Current Terminal Session:
** Permanently:
~/.bash_profile
usingvi ~/.bash_profile
and add this line to it: export PATH="~/Library/Android/sdk/platform-tools":$PATHHowever, 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 somewhere else, determine its location by going to:
Add it to System Path
When you have determined ADB's location, add it to system, follow this syntax and type it in terminal:
(in macOS)
export PATH="your/path/to/adb/here":$PATH
for example: export PATH="~/Library/Android/sdk/platform-tools":$PATH
这就是它首先对我起作用的方式
,我发现我的平台工具比我使用 zshrc 而不是 bash_profile 所以我首先运行此命令,
然后刷新终端
检查它是否有效,
此命令的结果必须是类似的如果是的话然后它起作用了。
This is how it worked for me
first I find my platform-tools than I was using zshrc instead of bash_profile so I run this command first
next refresh terminal
Check if it worked
result of this command must be something similar to this if so then it worked.
我不知道你是如何安装android SDK的。但在 Mac OS 中,真正对我有用的是使用brew 重新安装它。所有的问题都一一解决了。
后来:
像一个魅力
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.
Later on:
Like a charm
如果您已在 MAC 上安装 Android Studio,请执行以下操作:
或
然后编辑文件
控件 + X 或保存文件。
重新启动终端并尝试
If you have installed Android Studio on MAC here is how:
or
Then edit the file
control + X OR Save file.
Restart Terminal and try
更新
正如@Loren.A在评论中提到的,最新版本的brew不支持
cast
。因此,可以简单地使用:brew install android-platform-tools
Simply install adb withbrew
brew 桶安装 android-platform-tools
检查adb是否已安装
adb 设备
UPDATE
As @Loren.A mentioned in comment latest version of brew does not support
cast
. So one can simply use:brew install android-platform-tools
Simply install adb with brew
brew cask install android-platform-tools
Check if adb is installed
adb devices
对我来说,我从 bash 切换到 zsh 后遇到了这个问题,这样我就可以使用 Hyper 让我的控制台看起来非常棒。 和 snazzy 主题。我试图使用
react-native run-android
运行我的react-native应用程序并遇到操作问题。将以下内容添加到我的~.zshrc
文件中解决了我的问题: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:如果您使用的是带有 M1 芯片的 Mac,请使用 nano 命令将以下导出命令添加到 zshrc 文件中,如果该文件不存在,nano 命令将为您创建它,因此运行
将此路径粘贴到该文件中,无需任何
修改ctrl-x,然后按 y 保存更改,然后按 return 键关闭它而不重命名文件。
然后运行
刷新 .zshrc 文件
,然后尝试运行
adb
它应该会给你想要的输出
If you are using the Mac with the M1 chip add the below export command to the zshrc file using the nano command, if that file is not present the nano command will create it for you so run
paste this path in that file without any modification
hit ctrl-x and then Hit y to save the changes and the hit return Key to close it without renaming the file.
then run
to refresh the .zshrc file
and then try runnning
adb
it should give you the desired output
如果您在 OS X 上使用
zsh
,则必须编辑 zshrc 文件。使用 vim 或您喜欢的文本编辑器打开 zshrc 文件:
将
adb
的路径粘贴到此文件中: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:
Paste the path to
adb
in this file:这对我的 MAC - 2020 有效
转到包含 adb 的目录:
运行 adb 命令列出所有服务
This worked for me on my MAC - 2020
Go to directory containing adb:
Run adb command to list all services
对于 Mac OS Catalina 或 Mojave
输入命令打开 Nano 编辑器
设置 PATH 变量,表示附加更多路径,如下所示
现在按 Command + X 将文件保存在编辑器中,输入 Yes 或 No 并按 Enter 键。
For Mac OS Catalina or Mojave
Enter command to open nano editor
Set PATH variable, means append more path as shown here
Now press Command + X to save file in editor,Enter Yes or No and hit Enter key.
我无法让愚蠢的路径工作,所以我为 abd 创建了一个别名,
效果很好。
I couldn't get the stupid path working so I created an alias for abd
works fine.
对于 Mac,Android Studio 3.6.1,我将其添加到 .bash_profile
export PATH="~/Library/Android/sdk/platform-tools/platform-tools":$PATH
For Mac, Android Studio 3.6.1, I added this to .bash_profile
export PATH="~/Library/Android/sdk/platform-tools/platform-tools":$PATH
或者替代解决方案可以是
/Users/your-user-name/Library/Android/sdk
如果 SDK 存在,则运行此命令。 ./platform-tools/adb install your-apk-location
从那里你可以生成 APK 文件 这是检查 adb 是否可用的唯一示例
命令就在那里
Or the alternative solution could be
/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
由于某种原因,安装
Android Studio 3.6.1
时,adb
文件实际上位于$ANDROID_HOME/platform-tools/platform-tools
中。不确定这是否是我的安装的错误或什么,但这为我修复了它。For some reason when installed
Android Studio 3.6.1
theadb
file was actually in$ANDROID_HOME/platform-tools/platform-tools
. not sure if this is a bug with my installation or what but this fixed it for me.对于 Mac OS,从 Mojave 及更高版本开始,默认 shell 已从“bash”转移到“zsh”,因此对于所有 Mac 用户,我建议创建“.zshrc”文件。 “adb”按预期运行。感谢@slhck 提供的信息。!
For Mac Os the default shell has moved on to "zsh" from "bash" as of Mojave and later releases, so for all the Mac users I would suggest go with the creating ".zshrc" file. "adb" runs as it is intended to be. Thanks @slhck for your info.!
按照以下步骤
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
在某些情况下,您可能需要在每次打开 cmd 运行 adb 命令时运行 source .bash_profile
Follow steps below
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
In some cases, you may need to run source .bash_profile every time you open cmd to run adb commands
唯一对我有用的是打开终端设置并将shell路径从 /bin/bash 更改为 /bin/zsh
The only thing that worked for me was opening the terminal settings and changing the shell path from /bin/bash to /bin/zsh
工作正常..
稍后:
It's working fine..
Later on: