在macOS上安装ADB [复制]

本文翻译自:Installing ADB on macOS [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

  • Set up adb on Mac OS X 17 answers 在Mac OS X上设置adb 17答案

I had issues finding a good solid tutorial on how to setup ADB for Mac. 我遇到了一些关于如何设置ADB for Mac的实用教程的问题。

How can I add ADB to macOS in such a way that it can be used in the terminal? 如何以可在终端中使用的方式将ADB添加到macOS


Unlike Set up adb on Mac OS X , the intention of this question is to have a tutorial with all of the required installation steps to get ADB on macOS. 与在Mac OS X上设置adb不同,此问题的目的是获得一个教程,其中包含在macOS上获取ADB所需的所有安装步骤。


#1楼

参考:https://stackoom.com/question/27dpd/在macOS上安装ADB-复制


#2楼

  1. You must download Android SDK from this link . 您必须从此链接下载Android SDK。

  2. You can really put it anywhere, but the best place at least for me was right in the YOUR USERNAME folder root. 你可以把它放在任何地方,但至少对我来说最好的地方就在你的USERNAME文件夹根目录中。

  3. Then you need to set the path by copying the below text, but edit your username into the path, copy the text into Terminal by hitting command + spacebar type terminal . 然后你需要通过复制下面的文本来设置路径,但是在路径中编辑你的用户名,通过命令 + spacebar type terminal将文本复制到终端 export PATH = ${PATH}:/Users/**YOURUSERNAME**/android-sdk/platform-tools/

  4. Verify ADB works by hitting command + spacebar and type terminal , and type ADB . 通过按命令 + 空格键并键入terminal验证ADB是否正常工作,然后键入ADB

There you go. 你去吧 You have ADB setup on MAC OS X. It works on latest MAC OS X 10.10.3. 您在MAC OS X上设置了ADB。它适用于最新的MAC OS X 10.10.3。


#3楼

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

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

  1. Install homebrew 安装自制软件

     ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
  2. Install adb 安装adb

     brew cask install android-platform-tools 
  3. 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 path 在您的路径中添加platform-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 - Manually (with SDK Manager) 选项3 - 手动(使用SDK Manager)

  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 获取命令行工具”下的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 Manager

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

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

  1. Add platform-tools to your path 在您的路径中添加platform-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 

#4楼

Note that if you use Android Studio and download through its SDK Manager, the SDK is downloaded to ~/Library/Android/sdk by default, not ~/.android-sdk-macosx . 请注意,如果您使用Android Studio并通过其SDK Manager下载,则SDK默认下载到~/Library/Android/sdk ,而不是~/.android-sdk-macosx

I would rather add this as a comment to @brismuth's excellent answer, but it seems I don't have enough reputation points yet. 我更愿意将此作为评论添加到@ brismuth的优秀答案,但似乎我还没有足够的声望点。


#5楼

Option 3 - Using MacPorts 选项3 - 使用MacPorts

Analoguously to the two options (homebrew / manual) posted by @brismuth, here's the MacPorts way: 类似于@brismuth发布的两个选项(自制/手动),这里是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. As @brismuth suggested, uncheck everything but Android SDK Platform-tools (optional) 正如@brismuth建议的那样,取消选中除Android SDK Platform-tools所有Android SDK Platform-tools (可选)

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

  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 

#6楼

If you've already installed Android Studio -- 如果您已安装Android Studio -

Add the following lines to the end of ~/.bashrc or ~/.zshrc (if using Oh My ZSH): 将以下行添加到~/.bashrc~/.zshrc .zshrc的末尾(如果使用Oh My ZSH):

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

Restart Terminal and you're good to go. 重启终端,你很高兴。

你可能感兴趣的:(android,macos,adb)