简体   繁体   English

在 Mac OS X 上设置 adb

[英]Set up adb on Mac OS X

I spent quite sometime figuring how to set up adb on Mac, so I figure writing how to set it up might be useful to some people.我花了很长时间研究如何在 Mac 上设置 adb,所以我认为编写如何设置它可能对某些人有用。 adb is the command line tool to install and run android apps on your phone/emulator adb 是在您的手机/模拟器上安装和运行安卓应用程序的命令行工具

Note: this was originally written on Installing ADB on macOS but that question was closed as a duplicate of this one.注意:这最初是在 macOS 上安装 ADB 上写的,但该问题已作为此问题的副本关闭。

Note for zsh users : replace all references to ~/.bash_profile with ~/.zshrc . zsh 用户注意事项:将所有对~/.bash_profile的引用替换为~/.zshrc

Option 1 - Using Homebrew选项 1 - 使用 Homebrew

This is the easiest way and will provide automatic updates.这是最简单的方法,将提供自动更新。

  1. Install homebrew安装自制软件

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. Install adb安装亚行

     brew install android-platform-tools

or try a cask install depending on your settings:或根据您的设置尝试木桶安装:

     brew install --cask android-platform-tools
  1. Start using adb开始使用 adb

     adb devices

Option 2 - Manually (just the platform tools)选项 2 - 手动(仅平台工具)

This is the easiest way to get a manual installation of ADB and Fastboot.这是手动安装 ADB 和 Fastboot 的最简单方法。

  1. Delete your old installation (optional)删除旧安装(可选)

     rm -rf ~/.android-sdk-macosx/
  2. Navigate to https://developer.android.com/studio/releases/platform-tools.html and click on the SDK Platform-Tools for Mac link.导航到https://developer.android.com/studio/releases/platform-tools.html并单击SDK Platform-Tools for Mac链接。

  3. Go to your Downloads folder转到您的下载文件夹

     cd ~/Downloads/
  4. Unzip the tools you downloaded解压你下载的工具

     unzip platform-tools-latest*.zip
  5. Move them somewhere you won't accidentally delete them将它们移动到不会意外删除它们的地方

     mkdir ~/.android-sdk-macosx mv platform-tools/ ~/.android-sdk-macosx/platform-tools
  6. Add platform-tools to your pathplatform-tools添加到您的路径

     echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile
  7. Refresh your bash profile (or restart your terminal app)刷新您的 bash 配置文件(或重新启动您的终端应用程序)

     source ~/.bash_profile
  8. Start using adb开始使用 adb

     adb devices

Option 3 - If you already have Android Studio installed选项 3 - 如果您已经安装了 Android Studio

  1. Add platform-tools to your pathplatform-tools添加到您的路径

     echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bash_profile
  2. Refresh your bash profile (or restart your terminal app)刷新您的 bash 配置文件(或重新启动您的终端应用程序)

     source ~/.bash_profile
  3. Start using adb开始使用 adb

     adb devices

Option 4 - MacPorts选项 4 - MacPorts

  1. Install the Android SDK:安装 Android SDK:

     sudo port install android
  2. Run the SDK manager:运行 SDK 管理器:

     sh /opt/local/share/java/android-sdk-macosx/tools/android
  3. Uncheck everything but Android SDK Platform-tools (optional)取消选中除Android SDK Platform-tools之外的所有内容(可选)

  4. Install the packages, accepting licenses.安装软件包,接受许可证。 Close the SDK Manager.关闭 SDK 管理器。

  5. Add platform-tools to your path;platform-tools添加到您的路径; in MacPorts, they're in /opt/local/share/java/android-sdk-macosx/platform-tools .在 MacPorts 中,它们位于/opt/local/share/java/android-sdk-macosx/platform-tools中。 Eg, for bash:例如,对于 bash:

     echo 'export PATH=$PATH:/opt/local/share/java/android-sdk-macosx/platform-tools' >> ~/.bash_profile
  6. Refresh your bash profile (or restart your terminal/shell):刷新您的 bash 配置文件(或重新启动您的终端/shell):

     source ~/.bash_profile
  7. Start using adb:开始使用 adb:

     adb devices

Option 5 - Manually (with SDK Manager)选项 5 - 手动(使用 SDK 管理器)

  1. Delete your old installation (optional)删除旧安装(可选)

     rm -rf ~/.android-sdk-macosx/
  2. Download the Mac SDK Tools from the Android developer site under "Get just the command line tools" .从 Android 开发人员站点的“仅获取命令行工具”下下载 Mac SDK 工具。 Make sure you save them to your Downloads folder.确保将它们保存到“下载”文件夹中。

  3. Go to your Downloads folder转到您的下载文件夹

     cd ~/Downloads/
  4. Unzip the tools you downloaded解压你下载的工具

     unzip tools_r*-macosx.zip
  5. Move them somewhere you won't accidentally delete them将它们移动到不会意外删除它们的地方

     mkdir ~/.android-sdk-macosx mv tools/ ~/.android-sdk-macosx/tools
  6. Run the SDK Manager运行 SDK 管理器

     sh ~/.android-sdk-macosx/tools/android
  7. Uncheck everything but Android SDK Platform-tools (optional)取消选中除Android SDK Platform-tools之外的所有内容(可选)

在此处输入图像描述

  1. Click Install Packages , accept licenses, click Install .单击Install Packages ,接受许可证,单击Install Close the SDK Manager window.关闭 SDK 管理器窗口。

在此处输入图像描述

  1. Add platform-tools to your pathplatform-tools添加到您的路径

     echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile
  2. Refresh your bash profile (or restart your terminal app)刷新您的 bash 配置文件(或重新启动您的终端应用程序)

     source ~/.bash_profile
  3. Start using adb开始使用 adb

     adb devices

echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile && source ~/.bash_profile

如果将 android-sdks 文件夹放在其他目录下,请将路径替换为 android-sdks/platform-tools 所在的目录

This Works Flawless....这工作完美无瑕....

In terminal Run both commands next to each other在终端中并排运行这两个命令

export ANDROID_HOME=/Users/$USER/Library/Android/sdk

export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Only for zsh users in iterm2 in macOS仅适用于 macOS 中 iterm2 中的 zsh 用户

type the following two commands to add the android sdk and platform-tools to your zsh in iterm2 in macOS键入以下两个命令,将 android sdk 和 platform-tools 添加到 macOS 中 iterm2 中的 zsh

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

After adding the two command to ~/.zshrc you need to source the zsh.将这两个命令添加到~/.zshrc后,您需要获取 zsh。

source ~/.zshrc

NOTE: Path for adb has changed since Android Studio 1.0.xx注意:自 Android Studio 1.0.xx 以来 adb 的路径已更改

For bash shell, use:对于bash shell,使用:

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

For tcsh shell, use:对于tcsh shell,使用:

echo 'setenv PATH $PATH\:'$HOME'/Library/Android/sdk/platform-tools' >> ~/.tcshrc

If you are using zsh shell and after trying all this solutions, you still need to set $PATH and $ANDROID_HOME every time you open new terminal instance, then here is your answer:如果您使用的是zsh shell ,并且在尝试了所有这些解决方案之后,您仍然需要在每次打开新终端实例时设置$PATH$ANDROID_HOME ,那么这就是您的答案:

step 1: in terminal run nano ~/.zshrc第 1 步:在终端运行nano ~/.zshrc

step 2: paste following command at the end of the file第2步:将以下命令粘贴到文件末尾

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

step 3: After copying the lines above, to save hit control + X .第 3 步:复制上面的行后,保存 hit control + X and to confirm hit Y .并确认命中Y It will ask you if you wish to change the file name but don't change the name so directly hit enter它会询问您是否要更改文件名,但不要更改名称,因此直接按Enter

step 4: Restart your terminal and execute the adb command.第 4 步:重新启动终端并执行 adb 命令。

Bingo!答对了!

Personally I just source my .bashrc in my .bash_profile:就我个人而言,我只是在我的 .bash_profile 中获取我的 .bashrc:

echo 'source ~/.bashrc' >> ~/.bash_profile

So I put it in my .bashrc.所以我把它放在我的 .bashrc 中。 And I'm using Android Studio, so it was a different path.我正在使用 Android Studio,所以这是一条不同的路径。

echo 'PATH=$PATH:$HOME/Library/Android/sdk/platform-tools/' >> ~/.bashrc

You may also want the following:您可能还需要以下内容:

echo 'ANDROID_HOME=$HOME/Library/Android/sdk' >> ~/.bashrc

Here is a step wise information :这是一步一步的信息:

Step-1步骤1

Start up Terminal and go to your home folder.启动终端并转到您的主文件夹。

cd ~/

Step-2第2步

Open and edit .bash_profile file打开并编辑 .bash_profile 文件

$ open -e .bash_profile

If you don't have .bash_profile file in your computer path, then create one.如果您的计算机路径中没有 .bash_profile 文件,请创建一个。 Enter below command to create a new file.输入以下命令以创建一个新文件。 Once created follow Step-2.创建后,请按照步骤 2。

touch .bash_profile

Step-3第三步

Save the below line)保存以下行)

export PATH=${PATH}:/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools
export PATH=${PATH}:/Applications/adt-bundle-mac-x86_64-20140321/sdk/platform-tools

Step-4第4步

Refresh the file using below command使用以下命令刷新文件

$ source .bash_profile

$ echo $PATH

You should see your android path set in the output now.您现在应该在输出中看到您的 android 路径设置。

The simplest way to use adb command on your Mac systems would be to add the path to the platform-tools (where adb lives) into your bash_profile.在 Mac 系统上使用 adb 命令的最简单方法是将平台工具(adb 所在的位置)的路径添加到 bash_profile 中。

Steps to add the adb path: 1. open the bash_profile: This can be done by using the following commands添加 adb 路径的步骤: 1. 打开 bash_profile:这可以通过使用以下命令来完成

open ~/.bash_profile

This opens up the bash_profile in an editor.这将在编辑器中打开 bash_profile。

  1. Locate the platform_tools, usually they are present at the following location: Users/"user_folder"/Library/Android/sdk/platform_tools找到platform_tools,它们通常位于以下位置:Users/"user_folder"/Library/Android/sdk/platform_tools

  2. Paste the following command in the bash_profile file which opens up:将以下命令粘贴到打开的 bash_profile 文件中:

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

  3. Save the file using the command:使用以下命令保存文件:

source ~/.bash_profile

  1. Check if the path is saved by typing: echo $PATH : You should be able to find the entire path displayed in the output.通过键入检查路径是否已保存: echo $PATH :您应该能够找到输出中显示的整个路径。

  2. Type adb to see if the configuration worked.键入adb以查看配置是否有效。 If you have any devices connected to the machine or any emulators running on your system they would be displayed when you type adb devices如果您有任何设备连接到机器或系统上运行的任何仿真器,它们将在您键入adb devices时显示

output for adb devices adb 设备的输出

For Mac users : Step 1: Install the Android Studio对于 Mac 用户:第 1 步:安装 Android Studio

Step2 : Open the terminal and type Step2:打开终端并输入

cd

Step 3: Type below mentioned command changing the userName:第 3 步:键入下面提到的更改用户名的命令:

export PATH=“/Users/{user_name}/Library/Android/sdk/platform-tools”:$PATH

cd sdk/platform-tools/然后使用./adb devices

On MacOS Big Sur do the following:在 MacOS Big Sur 上执行以下操作:

Open config file:打开配置文件:

nano ~/.zshrc

Add paths to PATH variable:将路径添加到 PATH 变量:

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

close file and save changes.关闭文件并保存更改。 Then in terminal write:然后在终端写:

source ~/.zshrc

And then you'll be able to run:然后你就可以运行了:

adb devices
adb kill-server

if you are using Android Studio in MAC OS X , you could exec the following command in your terminal app:如果您在 MAC OS X 中使用 Android Studio,您可以在终端应用程序中执行以下命令:

echo 'alias adb="/Applications/Android\ Studio.app/sdk/platform-tools/adb"' >> .bashrc
exec $SHELL

and next:接下来:

adb devices

and you should be showing a list with your android devices connected via USB cable in your MAC, for example something like this:您应该在 MAC 中显示通过 USB 电缆连接的 android 设备的列表,例如:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
deb7bed5        device

If you using zsh then you need do the add the following to your .zshrc如果您使用 zsh,那么您需要将以下内容添加到您的 .zshrc

Steps: Step 1: Open your .zshrc profile步骤: 第 1 步:打开您的 .zshrc 个人资料

open -e .zshrc

Step 2: Add the following to the file步骤2:将以下内容添加到文件中

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

Step 3: Save the file and close.第三步:保存文件并关闭。 Step 4: Reload the .zshrc第 4 步:重新加载 .zshrc

source .zshrc

Step 5: Check the devices connected第 5 步:检查连接的设备

adb devices

MAC Solution. MAC解决方案。

cd /Users/<user>/Library/Android/sdk/platform-tools
./adb devices

2022 Solution 2022解决方案

If you have Android Studio installed already and Terminal isn't picking up ADB, here's a one-liner that should fix it:如果你已经安装了 Android Studio 并且终端没有选择 ADB,这里有一个可以修复它的单行代码:

sudo ln -s ~/Library/Android/sdk/platform-tools/adb /usr/local/bin

For macOS Users Updated to MacOs Catalina,对于更新到 MacOs Catalina 的 macOS 用户,

~/.bash_profile changed to ~/.zshrc ~/.bash_profile更改为~/.zshrc

So ,to run adb command and all other commands already exported to ~/.bash_profile easy walkaround is to export bash_profile to zshrc因此,要运行adb命令和所有其他已导出到~/.bash_profile的命令,简单的解决方法是将 bash_profile 导出到zshrc

To do that,要做到这一点,

1) Navigate to the home directory in finder 1)导航到finder中的主目录

2) I used Cmd + Shift + . 2)我使用 Cmd + Shift + 。 to show the hidden files in Finder在 Finder 中显示隐藏文件

3) Create .zshrc file if already not exist 3) 如果不存在,则创建 .zshrc 文件

4) Add line "source ~/.bash_profile" without quotes 4) 添加不带引号的“source ~/.bash_profile”行

5) Save 5) 保存

6) Quit and open terminal 6)退出并打开终端

start using adb devices开始使用adb 设备

Here's a detailed manual:这里有一份详细的手册:
http://codexpi.com/add-android-adb-path-mac-os-x-mavericks/ http://codexpi.com/add-android-adb-path-mac-os-x-mavericks/

To sum this up:总结一下:

  1. Create and open the bash_profile file创建并打开 bash_profile 文件

    touch .bash_profile
    open -e .bash_profile

  2. Add the path of the platform-tools folder (within the Android SDK)添加 platform-tools 文件夹的路径(在 Android SDK 中)

    export PATH="$PATH:/Users/USERNAME/PATH TO ANDROID SDK/platform-tools/

  3. Run the command . .bash_profile运行命令. .bash_profile . .bash_profile to update (no need to restart the terminal) . .bash_profile更新(无需重启终端)

如果您正在使用 ZSH 并拥有 Android Studio 1.3: 1. 打开 .zshrc 文件(位于您的主目录中,文件是隐藏的,因此请确保您可以看到隐藏文件) 2. 在末尾添加此行: alias adb="/Users/kamil/Library/Android/sdk/platform-tools/adb" 3. 退出终端 4. 打开终端并输入adb devices 5. 如果它有效,它将为您提供所有连接设备的列表

Mac OS Open Terminal Mac OS 打开终端

touch ~/.bash_profile; open ~/.bash_profile

Copy and paste:复制和粘贴:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

command + S for save. command + S 保存。

If you are setting the path in Catalina use below command one after another in the terminal.如果您在 Catalina 中设置路径,请在终端中依次使用以下命令。 It's working fine for me.它对我来说很好。

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

source ~/.bash_profile

Commenting with some updated information from 2018.评论 2018 年的一些更新信息。

Executable Binaries for Platform tools are made available for mac by Android here: https://developer.android.com/studio/releases/platform-tools.html平台工具的可执行二进制文件可在此处通过 Android 用于 Mac: https ://developer.android.com/studio/releases/platform-tools.html

Download these to your mac.将这些下载到您的 Mac。 Place them in a directory eg I placed in ~/Software/platform-tools将它们放在一个目录中,例如我放在~/Software/platform-tools

If you have root access , the easiest way I have found on a mac is to add your directories to the list in /etc/paths .如果您有 root 访问权限,我在 mac 上找到的最简单的方法是将您的目录添加到/etc/paths的列表中。 I like this way because after a few additions the $PATH starts to look too messy and hard to read, the /etc/paths has everything in separate line, clean and organized.我喜欢这种方式,因为在添加了几次之后, $PATH开始显得过于凌乱且难以阅读,而/etc/paths将所有内容都放在单独的行中,干净且有条理。 The downside is that you require root access.缺点是您需要root访问权限。

$ cat /etc/paths  # check contents of the file
$ sudo nano /etc/paths

Paste the full path of your platform-tools directory (something like /Users/GodZilla/Software/platform-tools/adb ) at the end of this list and save.将您的平台工具目录的完整路径(类似于/Users/GodZilla/Software/platform-tools/adb )粘贴到此列表的末尾并保存。 Quit and Open terminal again and check if it sees your platform-tools directory.再次退出并打开终端并检查它是否看到您的平台工具目录。

$ which adb
/Users/GodZilla/Software/platform-tools/adb
$ which fastboot
/Users/GodZilla/Software/platform-tools/fastboot

If you don't have root access, just add the platform-tools directory to $PATH in your .bash_profile (or .zshenv if you use zsh) as other users have suggested.如果您没有 root 访问权限,只需按照其他用户的建议将 platform-tools 目录添加到 .bash_profile(或 .zshenv,如果您使用 zsh)中的$PATH即可。

This totally worked for me, after dickering around for a while after installing Android Studio:这对我来说完全有用,在安装 Android Studio 后折腾了一段时间后:

  1. Make sure you have the .bash_profile file.确保您拥有 .bash_profile 文件。 This should be in your [username] directory.这应该在您的 [用户名] 目录中。

  2. From whatever directory you are on, type this:从您所在的任何目录中,输入以下内容:

     echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile

Now, usually you will have this exact path, but if not, then use whatever path you have the platform-tools folder现在,通常你会有这个确切的路径,但如果没有,那么使用你有 platform-tools 文件夹的任何路径

  1. From the directory where your .bash_profile resides, type this:在 .bash_profile 所在的目录中,键入:

     . .bash_profile
  2. Now type adb devices .现在输入adb devices You should see a "List of devices attached" response.您应该会看到“连接的设备列表”响应。 Now you do not have to go to the platform-tools directory each and every time to type in the more cryptic command like, ./adb devices !!!现在您不必每次都去平台工具目录输入更神秘的命令,例如./adb devices !!!

In my case, I installed Android studio, and have some apps (rust lang) that changes the ~/.profile , and adding adb to ~/.bash_profile made the rust un-executable, so I made the changes to the ~/.profile only, as:就我而言,我安装了 Android Studio,并且有一些应用程序(rust lang)会更改~/.profile ,并将adb添加到~/.bash_profile使 rust 无法执行,所以我对 ~/.profile 进行了更改~/.profile~/.profile ,如:

$ echo 'PATH=$PATH:$HOME/Library/Android/sdk/platform-tools/' >> ~/.profile
$ source ~/.profile
$ adb --version
Android Debug Bridge version 1.0.41
Version 29.0.4-5871666
Installed as /Users/hasan/Library/Android/sdk/platform-tools/adb

In my case : I did the following (on a mac) :就我而言:我做了以下(在mac上):

  1. backed up the ".bash_profile" and ".profile"备份了“.bash_profile”和“.profile”
  2. cleared all the android related paths.清除所有与android相关的路径。
  3. created the new paths but this time around, I dragged the respective folders : { /.../sdk, /.../tools, /.../platform-tools } into the terminal.创建了新路径,但这一次,我将各自的文件夹: { /.../sdk, /.../tools, /.../platform-tools } 拖到终端中。 I did this for both ".bash_profile" and ".profile".我为“.bash_profile”和“.profile”做了这个。
  4. Then after successfully saving the files each.然后在成功保存文件后。 I restarted the terminal just to be sure about the modifications I made.我重新启动终端只是为了确定我所做的修改。
  5. I then went on to test if adb was responding now ... by typing : (in terminal) adb devices然后我继续测试 adb 现在是否响应......通过输入:(在终端中)adb devices
  6. I still had no luck (my devices) where not showing, then I restarted the adb, still.我仍然没有运气(我的设备)没有显示,然后我仍然重新启动了 adb。
  7. I went on to do "android update adb" .我继续做“android update adb”。 This just killed and restarted the adb这只是杀死并重新启动了 adb
  8. I tried again still the devices wasnt showing.我再次尝试仍然没有显示设备。
  9. I totally backed up my android device and resetted the whole phone back to factory default, went over to activate the device for development and allow for usb debugging in its settings > applications.我完全备份了我的 android 设备并将整个手机重置为出厂默认设置,继续激活设备进行开发并允许在其设置 > 应用程序中进行 USB 调试。

******** WORKED LIKE A CHARM ******** ******** 像魅力一样工作 ********

I tried again with the command "adb devices" and everything was back to normal the device was visible.我再次尝试使用命令“adb devices”,一切恢复正常,设备可见。

All the best.一切顺利。 Just dont give up.只是不要放弃。 It took me a lot of troubleshooting.我花了很多时间进行故障排除。 All the best of luck.祝你好运。

If you are using zsh terminal do the following:如果您使用的是 zsh 终端,请执行以下操作:

1) Open .zprofile file with the editor of your choice like "open -a xcode ~/.zprofile" 1) 使用您选择的编辑器打开 .zprofile 文件,例如“open -a xcode ~/.zprofile”

2) Add new PATH or Env Variable in .zprofile Save the file and quit the editor. 2) 在 .zprofile 中添加新的 PATH 或 Env 变量保存文件并退出编辑器。

3) Execute your .zprofile to update your PATH: source ~/.zprofile 3) 执行你的 .zprofile 来更新你的 PATH: source ~/.zprofile

Add environment variable for Android Home Targetting Platform Tools为 Android Home Targetting Platform Tools 添加环境变量

echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile

echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bash_profile

Restart Bash重启 Bash

source ~/.bash_profile

Now Check adb现在检查 adb

Simply type只需键入

adb

on terminal在终端上

After trying all the solutions, none of them where working for me.在尝试了所有解决方案之后,没有一个对我有用。

In my case I had the Android Studio and the adb was correctly working but the Android Studio was not capable to detect the adb.就我而言,我有 Android Studio 并且 adb 工作正常,但 Android Studio 无法检测到 adb。 These was because I installed it with homebrew in another directory, not the /Users/$USER/Library/Android/sdk but Usr/Library blabla这是因为我用自制软件将它安装在另一个目录中,而不是 /Users/$USER/Library/Android/sdk 而是 Usr/Library blabla

Apparently AS needed to have it in his route /Users/$USER/Library/Android/sdk (same place as in preferences SDK installation route)显然 AS 需要在他的路线 /Users/$USER/Library/Android/sdk 中拥有它(与偏好 SDK 安装路线中的相同位置)

So I deleted all the adb from my computer (I installed several) and executed these terminal commands:所以我从我的电脑中删除了所有的 adb(我安装了几个)并执行了这些终端命令:

echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile
echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bash_profile
source ~/.bash_profile
adb devices

Well, after that, still wasn't working, because for some reason the route for the adb was /Users/$USER/Library/Android/sdk/platform-tools/platform-tools (yes, repeated) so I just copied the last platform-tools into the first directory with all the license files and started working.好吧,在那之后,仍然无法正常工作,因为由于某种原因,adb 的路线是 /Users/$USER/Library/Android/sdk/platform-tools/platform-tools (是的,重复了)所以我只是复制了最后将平台工具放入包含所有许可证文件的第一个目录并开始工作。

Weird but true奇怪但真实

Considering you have already downloaded SDK platform tools.考虑到您已经下载了 SDK 平台工具。

This command will set ADB locally.此命令将在本地设置 ADB。 So if you close the terminal and open it again, ADB commands won't work until you run this command again.因此,如果您关闭终端并再次打开它,ADB 命令将无法工作,直到您再次运行此命令。

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

These commands will set ADB globally.这些命令将全局设置 ADB。 So once you run these commands no need to set them again next time.因此,一旦您运行这些命令,下次就无需再次设置它们。

echo 'export PATH=$PATH:~/Library/Android/sdk/platform-tools/' >> ~/.bash_profile

source ~/.bash_profile

Download Andriod Platform Tools for macOS from:从以下位置下载适用于 macOS 的 Andriod 平台工具:

https://developer.android.com/studio/releases/platform-toolshttps://developer.android.com/studio/releases/platform-tools

Extract to your somewhere eg ~/installs/platform-tools提取到您的某个地方,例如~/installs/platform-tools

Add that folder to path by running:通过运行将该文件夹添加到路径:

echo 'export PATH=$PATH:~/installs/platform-tools' >> ~/.zshrc

Either restart terminal or run:重新启动终端或运行:

source ~/.zshrc

Assuming that you are using zsh.假设您使用的是 zsh。

MacPorts MacPorts

It seems like android-platform-tools was first added to MacPorts only very recently — in 2018-10-20, under java/android-platform-tools/Portfile :似乎android-platform-tools只是最近才首次添加到 MacPorts 中——在 2018 年 10 月 20 日,在java/android-platform-tools/Portfile

It would appear that it relies on a compiled binary that's provided by Google;看起来它依赖于谷歌提供的编译二进制文件; it would appear that the source code for the binary might not be available.看起来二进制文件的源代码可能不可用。

The adb binary adb二进制文件

Reverse-engineering the android-platform-tools/Portfile from above reveals that the following archive is fetched from Google in order to build the port:从上面对android-platform-tools/Portfile进行逆向工程显示,为了构建端口,从 Google 获取了以下存档:

The abd binary is pre-compiled, available in platform-tools/adb within the above archive, which is a Mach-O 64-bit executable x86_64 , as per file(1) . abd二进制文件是预编译的,可在上述存档中的platform-tools/adb中获得,它是Mach-O 64-bit executable x86_64 ,根据file(1) It's ready to be used and doesn't seem to have any external dependencies (eg, doesn't look like it depends on java or anything).它已经准备好使用并且似乎没有任何外部依赖项(例如,看起来它不依赖于 java 或任何东西)。

Using adb使用adb

In order to use adb to restart the device, for example, in case the power button is stuck, the following steps could be used:为了使用adb重启设备,例如,在电源按钮卡住的情况下,可以使用以下步骤:

cd /tmp
curl https://dl.google.com/android/repository/platform-tools_r28.0.1-darwin.zip -o apt.zip
unzip apt.zip
./platform-tools/adb devices
./platform-tools/adb reboot

Upon first use since a reboot, you also have to first confirm the pairing with the phone through the Allow USB debugging?重启后首次使用时,您还必须先通过允许 USB 调试确认与手机配对? popup on the phone (phone has to have USB debugging enabled through the Developer Options , no root access required).手机上的弹出窗口(手机必须通过开发人员选项启用USB 调试,无需 root 访问权限)。

Step 1 : Open Terminal第 1 步:打开终端

Step 2 : Run command :第 2 步:运行命令:

 touch ~/.bash_profile; open ~/.bash_profile

Step 3 : This will open textEdit file when you can add following command:第 3 步:当您可以添加以下命令时,这将打开 textEdit 文件:

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

Blockquote块引用

Note : sharan is my user name check that on y our system and replace that with sharan rest will be same.注意: sharan 是我的用户名,检查在我们的系统上并用 sharan rest 替换它是一样的。 You can also find that by opening android studio你也可以通过打开android studio找到

   File->Project Structure..->SDK Location

Under Android SDK location there is path of sdk copy that and paste that on file and save it by pressing Command+S在 Android SDK 位置下有 sdk 复制的路径并将其粘贴到文件中并按 Command+S 保存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM