无法通过终端访问 OS X 中的 adb,“找不到命令”

发布于 2024-12-07 03:17:30 字数 447 浏览 1 评论 0原文

我已经在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

叹梦 2024-12-14 03:17:30

问题是:adb 不在您的 PATH 中。 这是 shell 查找可执行文件的位置。您可以使用 echo $PATH 检查当前的 PATH

Bash 将首先尝试在您的路径中而不是在当前目录中查找名为 adb 的二进制文件。因此,如果您当前位于 platform-tools 目录中,只需调用

./adb --help

点是您的当前目录,这会告诉 Bash 从那里使用 adb

但实际上,您应该将 platform-tools 添加到您的 PATH 中,以及 Android SDK 附带的一些其他工具。操作方法如下:

  1. 找出 Android SDK 的安装位置。这可能是(其中 $HOME 是您用户的主目录)以下之一(或通过 Android Studio 启动屏幕中的配置 > SDK 管理器进行验证):

    • Linux:$HOME/Android/Sdk
    • macOS:$HOME/Library/Android/sdk
  2. 找出要编辑的 shell 配置文件,取决于使用哪个文件

    • Linux:通常是$HOME/.bashrc
    • macOS:通常是$HOME/.bash_profile
    • 使用 Zsh:$HOME/.zshrc
  3. 打开第二步中的 shell 配置文件,然后在文件底部添加以下行。如果路径不同,请确保将路径替换为安装 platform-tools 的路径:

    导出 ANDROID_HOME="$HOME/Android/Sdk"
    导出 PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
    
  4. 保存配置文件,然后重新启动终端或运行source ~/. bashrc (或您刚刚修改的任何内容)。

请注意,某些第三方框架需要设置 ANDROID_HOME,因此添加它并没有什么坏处。

The problem is: 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.

But actually, you should add platform-tools to your PATH, as well as some other tools that the Android SDK comes with. This is how you do it:

  1. 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
  2. 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
  3. 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"
    
  4. 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.

冰火雁神 2024-12-14 03:17:30

对于 zsh 用户。将 alias adb='/Users/$USER/Library/Android/sdk/platform-tools/adb' 添加到 .zshrc 文件中。

然后运行source ~/.zshrc命令

For zsh users. Add alias adb='/Users/$USER/Library/Android/sdk/platform-tools/adb' to .zshrc file.

Then run source ~/.zshrc command

眼前雾蒙蒙 2024-12-14 03:17:30
  1. 在终端中运行命令nano $HOME/.zshrc

  2. 必须包含下一行:

    导出 PATH=$PATH:~/Library/Android/sdk/platform-tools
    导出 ANDROID_HOME=~/Library/Android/sdk
    导出 PATH="$HOME/.bin:$PATH"
    导出 PATH="~/Library/Android/sdk/platform-tools":$PATH
    
  3. 按 Ctrl + X 将文件保存在编辑器中,输入 Yes 或 No,然后按 Enter 键

  4. 运行 source ~/.zshrc

  5. 在终端中检查adb,运行adb

  1. run command in terminal nano $HOME/.zshrc

  2. Must include next lines:

    export PATH=$PATH:~/Library/Android/sdk/platform-tools
    export ANDROID_HOME=~/Library/Android/sdk
    export PATH="$HOME/.bin:$PATH"
    export PATH="~/Library/Android/sdk/platform-tools":$PATH
    
  3. Press Ctrl + X to save file in editor,Enter Yes or No and hit Enter key

  4. Run source ~/.zshrc

  5. Check adb in terminal, run adb

女皇必胜 2024-12-14 03:17:30

除了 slhck 之外,这对我(mac)也有用。

检查您的 sdk 所在位置。

  1. 打开 Android studio 并转到:

文件->项目结构-> SDK位置

  1. 复制路径。

  2. 在您的家中创建隐藏的.bash_profile

  3. (使用 vimopen -e 打开它)并使用以下命令:

export PATH=/Users/<Your session name>/Library/Android/sdk/platform-tools:/Users/<Your session name>/Library/Android/sdk/tools:$PATH

  1. 然后只需在终端中使用它:。 ~/.bash_profile

关于如何查找 adb 设备的帖子

In addition to slhck, this is what worked for me (mac).

To check where your sdk is located.

  1. Open Android studio and go to:

File -> Project Structure -> Sdk location

  1. Copy the path.

  2. Create the hidden .bash_profile in your home.

  3. (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

  1. Then simply use this in your terminal: . ~/.bash_profile

SO post on how to find adb devices

肥爪爪 2024-12-14 03:17:30

快速解答

在终端中粘贴此命令可以解决大多数情况下的问题:

** 对于当前终端会话:

  • (在 macOS 中) export PATH="~/Library/Android/sdk/platform-tools ":$PATH
  • (在 Windows 中) 我会尽快更新

** 永久:

  • (在 macOS 中) 编辑 ~/.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 中) ~/Library/Android/sdk/platform-tools
    • (在 Windows 中) 我会尽快更新

  • 如果您已在其他位置安装了 Android Studio,请通过以下方式确定其位置:

    • (在 macOS 中) Android Studio >首选项>外观和行为>系统设置> Android SDK 并注意显示以下内容的框:Android SDK 位置
    • (在 Windows 中) 我会尽快更新

  • 但是 Android SDK可以在没有 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:

  • (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

  • If you have installed Android Studio somewhere else, determine its location by going to:

    • (in macOS) Android Studio > Preferences > Appearance And Behavior > System Settings > Android SDK and pay attention to the box that says: Android SDK Location
    • (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:

  • (in macOS)

    export PATH="your/path/to/adb/here":$PATH

    for example: export PATH="~/Library/Android/sdk/platform-tools":$PATH

心奴独伤 2024-12-14 03:17:30

输入图像描述这里这就是它首先对我起作用的方式

,我发现我的平台工具比我使用 zshrc 而不是 bash_profile 所以我首先运行此命令,

echo 'export PATH=${PATH}:$HOME/Library/Android/sdk/platform-tools/' >> ~/.zshrc

然后刷新终端

source ~/.zshrc

检查它是否有效,

adb devices

此命令的结果必须是类似的如果是的话然后它起作用了。

List of devices attached
emulator-5554   device

enter image description hereThis 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

echo 'export PATH=${PATH}:$HOME/Library/Android/sdk/platform-tools/' >> ~/.zshrc

next refresh terminal

source ~/.zshrc

Check if it worked

adb devices

result of this command must be something similar to this if so then it worked.

List of devices attached
emulator-5554   device
何止钟意 2024-12-14 03:17:30

我不知道你是如何安装android SDK的。但在 Mac OS 中,真正对我有用的是使用brew 重新安装它。所有的问题都一一解决了。

brew install --cask android-sdk

后来:

android update sdk --no-ui --filter 'platform-tools'

像一个魅力

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 install --cask android-sdk

Later on:

android update sdk --no-ui --filter 'platform-tools'

Like a charm

郁金香雨 2024-12-14 03:17:30

如果您已在 MAC 上安装 Android Studio,请执行以下操作:

nano ~/.zshrc

open ~/.zshrc in VScode

然后编辑文件

# Android ADB
export ANDROID_HOME="$HOME/Library/Android/sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

控件 + X 或保存文件。
重新启动终端并尝试

> adb

If you have installed Android Studio on MAC here is how:

nano ~/.zshrc

or

open ~/.zshrc in VScode

Then edit the file

# Android ADB
export ANDROID_HOME="$HOME/Library/Android/sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

control + X OR Save file.
Restart Terminal and try

> adb
滥情哥ㄟ 2024-12-14 03:17:30

更新

正如@Loren.A在评论中提到的,最新版本的brew不支持cast。因此,可以简单地使用:

brew install android-platform-tools


  1. Simply install adb withbrew

    brew 桶安装 android-platform-tools

  2. 检查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


  1. Simply install adb with brew

    brew cask install android-platform-tools

  2. Check if adb is installed

    adb devices

帅冕 2024-12-14 03:17:30

对我来说,我从 bash 切换到 zsh 后遇到了这个问题,这样我就可以使用 Hyper 让我的控制台看起来非常棒。 snazzy 主题。我试图使用 react-native run-android 运行我的react-native应用程序并遇到操作问题。将以下内容添加到我的 ~.zshrc 文件中解决了我的问题:

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

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
佼人 2024-12-14 03:17:30

如果您使用的是带有 M1 芯片的 Mac,请使用 nano 命令将以下导出命令添加到 zshrc 文件中,如果该文件不存在,nano 命令将为您创建它,因此运行

nano ~/.zshrc

将此路径粘贴到该文件中,无需任何

export PATH="/Users/$USER/Library/Android/sdk/platform-tools":$PATH

修改ctrl-x,然后按 y 保存更改,然后按 return 键关闭它而不重命名文件。

然后运行

source ~/.zshrc

刷新 .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

nano ~/.zshrc

paste this path in that file without any modification

export PATH="/Users/$USER/Library/Android/sdk/platform-tools":$PATH

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

source ~/.zshrc

to refresh the .zshrc file

and then try runnning

adb

it should give you the desired output

忆沫 2024-12-14 03:17:30

如果您在 OS X 上使用 zsh,则必须编辑 zshrc 文件。

使用 vim 或您喜欢的文本编辑器打开 zshrc 文件:

vim ~/.zshrc

adb 的路径粘贴到此文件中:

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

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
九公里浅绿 2024-12-14 03:17:30

这对我的 MAC - 2020 有效

转到包含 adb 的目录:

cd ~/Library/Android/sdk/platform-tools/

运行 adb 命令列出所有服务

./adb shell dumpsys activity services

This worked for me on my MAC - 2020

Go to directory containing adb:

cd ~/Library/Android/sdk/platform-tools/

Run adb command to list all services

./adb shell dumpsys activity services
金兰素衣 2024-12-14 03:17:30

对于 Mac OS Catalina 或 Mojave

输入命令打开 Nano 编辑器

nano $HOME/.zshrc

设置 PATH 变量,表示附加更多路径,如下所示

FLUTTER_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin"
DART_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin/cache/dart-sdk/bin"
ANDROID_SDK_HOME="/Users/pankaj/Library/Android/sdk"
ANDROID_ADB_HOME="/Users/pankaj/Library/Android/sdk/platform-tools"

PATH="$PATH:$FLUTTER_HOME"
PATH="$PATH:$DART_HOME"
PATH="$PATH:$ANDROID_SDK_HOME"
PATH="$PATH:$ANDROID_ADB_HOME"

现在按 Command + X 将文件保存在编辑器中,输入 Yes 或 No 并按 Enter 键。

For Mac OS Catalina or Mojave

Enter command to open nano editor

nano $HOME/.zshrc

Set PATH variable, means append more path as shown here

FLUTTER_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin"
DART_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin/cache/dart-sdk/bin"
ANDROID_SDK_HOME="/Users/pankaj/Library/Android/sdk"
ANDROID_ADB_HOME="/Users/pankaj/Library/Android/sdk/platform-tools"

PATH="$PATH:$FLUTTER_HOME"
PATH="$PATH:$DART_HOME"
PATH="$PATH:$ANDROID_SDK_HOME"
PATH="$PATH:$ANDROID_ADB_HOME"

Now press Command + X to save file in editor,Enter Yes or No and hit Enter key.

永言不败 2024-12-14 03:17:30

我无法让愚蠢的路径工作,所以我为 abd 创建了一个别名,

alias abd ="~/Library/Android/sdk/platform-tools/adb"

效果很好。

I couldn't get the stupid path working so I created an alias for abd

alias abd ="~/Library/Android/sdk/platform-tools/adb"

works fine.

情徒 2024-12-14 03:17:30

对于 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

秉烛思 2024-12-14 03:17:30

或者替代解决方案可以是

  1. 确保您已经安装了 android SDK。通常它位于
    /Users/your-user-name/Library/Android/sdk
  2. 如果 SDK 存在,则运行此命令。 ./platform-tools/adb install your-apk-location

  3. 从那里你可以生成 APK 文件 这是检查 adb 是否可用的唯一示例
    命令就在那里

Or the alternative solution could be

  1. Make sure you already install for android SDK. Usually it is located under
    /Users/your-user-name/Library/Android/sdk
  2. If the SDK is there then run this command. ./platform-tools/adb install your-apk-location

  3. From there you can generate the APK file That's the only sample to check if adb
    command is there

一场信仰旅途 2024-12-14 03:17:30

由于某种原因,安装 Android Studio 3.6.1 时,adb 文件实际上位于 $ANDROID_HOME/platform-tools/platform-tools 中。不确定这是否是我的安装的错误或什么,但这为我修复了它。

For some reason when installed Android Studio 3.6.1 the adb 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.

谁人与我共长歌 2024-12-14 03:17:30

对于 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.!

許願樹丅啲祈禱 2024-12-14 03:17:30

按照以下步骤

  • 使用 open -e .bash_profile
  • write 打开 bash_profile
    export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
  • close bash_profile file
  • run source .bash_profile
  • 完成运行现在 adb 命令!!

在某些情况下,您可能需要在每次打开 cmd 运行 adb 命令时运行 source .bash_profile

Follow steps below

  • Open bash_profile using open -e .bash_profile
  • write
    export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
  • close bash_profile file
  • run source .bash_profile
  • Done run your adb command now !!

In some cases, you may need to run source .bash_profile every time you open cmd to run adb commands

是你 2024-12-14 03:17:30

唯一对我有用的是打开终端设置并将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
enter image description here

enter image description here

刘备忘录 2024-12-14 03:17:30

工作正常..

brew install android-sdk

稍后:

android update sdk --no-ui --filter 'platform-tools'

It's working fine..

brew install android-sdk

Later on:

android update sdk --no-ui --filter 'platform-tools'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文