简体   繁体   English

试图将 adb 添加到 PATH 变量 OSX

[英]Trying to add adb to PATH variable OSX

I am trying to develop for android and I want to add the adb to my PATH so that I can launch it really easily.我正在尝试为 android 进行开发,并且我想将adb添加到我的PATH以便我可以非常轻松地启动它。 I have added directories before by for some reason adb does not want to be found.我之前添加了目录,由于某种原因adb不想被发现。 This is very frustrating.这非常令人沮丧。 Has anyone else had this problem before?以前有没有其他人遇到过这个问题?

I created a file .profile and added the following to it.我创建了一个文件.profile并向其中添加了以下内容。

export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/platform-tools/
export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/tools

When I check my environment path I see the following:当我检查我的环境路径时,我看到以下内容:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Libs/android-sdk-mac_x86/tools:/Libs/android-sdk-mac_x86/platform-tools

So I know that it is added to my PATH variable.所以我知道它已添加到我的PATH变量中。 Now when I try to run adb I get that it is not found.现在,当我尝试运行adb时,我发现它找不到。

-bash: ./adb: No such file or directory

This is very very frustrating.这是非常非常令人沮丧的。 Could it be a problem with permissions?会不会是权限问题? Has anyone had this problem with OSX and Android?有人对 OSX 和 Android 有这个问题吗?

Add to PATH for every login为每次登录添加到 PATH

Total control version :总控制版本

in your terminal, navigate to home directory在您的终端中,导航到主目录

cd光盘

create file .bash_profile创建文件 .bash_profile

touch .bash_profile触摸 .bash_profile

open file with TextEdit用 TextEdit 打开文件

open -e .bash_profile打开 -e .bash_profile

insert line into TextEdit在 TextEdit 中插入行

export PATH=$PATH:/Users/ username /Library/Android/sdk/platform-tools/导出 PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/

save file and reload file保存文件并重新加载文件

source ~/.bash_profile源 ~/.bash_profile

check if adb was set into path检查 adb 是否设置为路径

adb version亚行版


One liner version一排版

Echo your export command and redirect the output to be appended to .bash_profile file and restart terminal.回显您的导出命令并将输出重定向到 .bash_profile 文件并重新启动终端。 (have not verified this but should work) (尚未验证这一点,但应该可以工作)

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

Alternative: Install adb the easy way替代方法:以简单的方式安装 adb

If you don't want to have to worry about your path or updating adb manually, you can use homebrew instead.如果您不想担心自己的路径或手动更新 adb,则可以改用自制软件

brew cask install android-platform-tools

Why are you trying to run "./adb"?你为什么要运行“./adb”? That skips the path variable entirely and only looks for "adb" in the current directory.这完全跳过了路径变量,只在当前目录中查找“adb”。 Try running "adb" instead.尝试运行“adb”。

Edit: your path looks wrong.编辑:您的路径看起来不对。 You say you get你说你得到

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Libs/android-sdk-mac_x86/tools:/Libs/android-sdk-mac_x86/platform-tools

You're missing the /Users/simon part.您缺少 /Users/simon 部分。

Also note that if you have both .profile and .bash_profile files, only the latter gets executed.另请注意,如果您同时拥有 .profile 和 .bash_profile 文件,则只会执行后者。

On my Macbook Pro, I've added the export lines to ~/.bash_profile, not .profile.在我的 Macbook Pro 上,我已将导出行添加到 ~/.bash_profile,而不是 .profile。

eg例如

export PATH=/Users/me/android-sdk-mac_86/platform-tools:/Users/me/android-sdk-mac_86/tools:$PATH

Just encase anyone finds this SO post when using Android Studio which includes the SDK has part of the App package (on Mac OSX).在使用包含 SDK 的 Android Studio 时,任何人都会发现此 SO 帖子,其中包含应用程序包的一部分(在 Mac OSX 上)。

So as @davecaunt and @user1281750 noted but insert the following line to .bash_profile正如@davecaunt 和@user1281750 指出的那样,但将以下行插入到 .bash_profile

export PATH=/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools:$PATH

The answer for MAC should be: MAC的答案应该是:

  1. Open your bash_profile with the following commands: open ~/.bash_profile使用以下命令打开您的 bash_profile: open ~/.bash_profile

  2. In case base profile file doesn't exist, create a new one with the following command: touch .bash_profile then repeat phase 1.如果基本配置文件不存在,请使用以下命令创建一个新文件: touch .bash_profile然后重复第 1 阶段。

  3. Add the following line: export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH添加以下行: export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH

  4. Restart your bash window and test by typing adb shell重新启动 bash 窗口并通过键入adb shell测试

Good luck!祝你好运! :-) :-)

In your terminal, navigate to home directory在您的终端中,导航到主目录

cd
create file .bash_profile

touch .bash_profile
open file with TextEdit

open -e .bash_profile
insert line into TextEdit

export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
save file and reload file

source ~/.bash_profile is very important check if adb was set into path source ~/.bash_profile检查 adb 是否设置为路径非常重要

adb version

It should be fine now.现在应该没问题了。

I use zsh and Android Studio.我使用 zsh 和 Android Studio。 I use a variable for my Android SDK path and configure in the file ~/.zshrc :我使用一个变量作为我的 Android SDK 路径并在文件~/.zshrc配置:

export ANDROID_HOME=/Applications/Android\ Studio.app/sdk
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"

Note: Make sure not to include single or double quotes around the specified path.注意:确保不要在指定路径周围包含单引号或双引号。 If you do, it won't work.如果你这样做,它就行不通了。

Android Studio v1.2 installs the adb tool in this path: Android Studio v1.2安装adb工具在这个路径:

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

So it goes like this:所以它是这样的:

  1. Run Terminal运行终端
  2. run adb version and expect an error output运行adb version并期待错误输出
  3. touch ~/.bash_profile
  4. open ~/.bash_profile
  5. add the above path before the 'closing' :$PATH在“关闭”之前添加上述路径:$PATH
  6. source ~/.bash_profile
  7. run adb version and expect an output运行adb version并期待输出

Good luck!祝你好运!

In order to make the terminal always have the file ~/.bashrc and there put the path you wish to use, by adding:为了使终端始终拥有文件~/.bashrc并在其中放置您希望使用的路径,通过添加:

export PATH=$PATH:/XXX

where XXX is the path that you wish to use.其中 XXX 是您希望使用的路径。

for adb, here's what i use:对于 adb,这是我使用的:

export PATH=$PATH:/home/user/Android/android-sdk-linux_x86/platform-tools/

(where "user" is my user name). (其中“用户”是我的用户名)。

It appears that you're still trying to execute adb with ./adb .看来您仍在尝试使用./adb执行adb That asks the shell to run the program named adb in the current working directory .这要求 shell在当前工作目录中运行名为adb的程序。

Try just adb without ./ .试试没有./ adb

在此处输入图片说明

2nd solution is explained below.下面解释第二个解决方案。 But when i close the terminal the change which i made in path variable gets lost.但是当我关闭终端时,我在路径变量中所做的更改丢失了。 Thus i prefer the first way!因此我更喜欢第一种方式!

在此处输入图片说明

I added export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/ into both places .bash_profile and .profile to make sure it works.我将export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/到两个地方.bash_profile.profile以确保它工作。 Still it wasn't working and then I looked at sarnold's tip about restarting terminal and it worked like a charm.仍然无法正常工作,然后我查看了sarnold关于重新启动终端的提示,它就像一个魅力。 It saved my time of adding every time this into the PATH whenever I had to run adb .每当我必须运行adb时,它都会节省我每次将其添加到PATH时间。 Thank you guys.谢谢你们。

If anyone can't seem to get there .bash_profile file to take any new Paths AND you have other commands in that file (like alias commands) then try moving the PATH statements to the top of the file.如果任何人似乎无法到达.bash_profile文件以获取任何新路径并且该文件中有其他命令(如别名命令),则尝试将 PATH 语句移动到文件顶部。

That is the only thing that worked for me.这是唯一对我有用的东西。 The reason it worked was because I had some typos in my alias commands and apparently this file throws an error and exits if it runs into a problem.它工作的原因是因为我的别名命令中有一些拼写错误,显然这个文件会抛出错误并在遇到问题时退出。 So that is why my PATH statements weren't being run.所以这就是我的 PATH 语句没有运行的原因。 Moving it to the top just let it run first.将它移动到顶部,让它先运行。

If you are Catalina user follow this如果您是 Catalina 用户,请遵循此

  1. Make sure to be in the Home directory确保在主目录中

    cd ~光盘~

  2. To persist PATH changes and prevent it to be cleaned up after closing the Terminal app, you need to keep the variables in the zshrc file for Catalina要保持 PATH 更改并防止在关闭终端应用程序后将其清除,您需要将变量保留在 Catalina 的 zshrc 文件中

    touch .zshrc触摸.zshrc

  3. Open it with the TextEditor使用文本编辑器打开它

    open -e .zshrc打开 -e .zshrc

  4. Insert the command below to add ADB as PATH variable (replace username with your own)插入下面的命令以将 ADB 添加为 PATH 变量(将用户名替换为您自己的)

    export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/导出 PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/

  5. Save the file and close the TextEditor app.保存文件并关闭 TextEditor 应用程序。 Back to the Terminal app, insert the following to source the file返回终端应用程序,插入以下内容以获取文件

    source .zshrc源.zshrc

  6. And you're done!你完成了! Let's test if it was successful让我们测试一下是否成功

    adb version亚行版

  7. You should expect something like你应该期待像

    Android Debug Bridge version 1.0.41 Version 31.0.2-7242960 Installed as /Users/username/Library/Android/sdk/platform-tools//adb Android Debug Bridge version 1.0.41 Version 31.0.2-7242960 安装为/Users/username/Library/Android/sdk/platform-tools//adb

In bash profile just add -在 bash 配置文件中添加 -

export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/导出 PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/

and then in terminal run -然后在终端运行 -

adb version亚行版

All answers are well written and helpful but there is one thing that I want to mention.所有答案都写得很好并且很有帮助,但我想提一件事。 Before adding path variable to .bash_profile kindly check your default shell.在将路径变量添加到.bash_profile之前,请检查您的默认 shell。

Because i was seting path variable in .bash_profile file but my default shell was zsh that's why i have to run source ~/.bash_profile each time before using adb command.因为我在.bash_profile文件中设置路径变量,但我的默认 shell 是zsh这就是为什么我必须在每次使用 adb 命令之前运行source ~/.bash_profile

So first check your default shell:所以首先检查你的默认 shell:

echo $SHELL
  • if the output is /bin/bash then you should set path variable in .bash_profile如果 output 是/bin/bash那么你应该在.bash_profile中设置路径变量
  • If the output is /bin/zsh then you should set path variable in .zshrc如果.zshrc/bin/zsh那么你应该在 .zshrc 中设置路径变量

And here is my path variable:这是我的路径变量:

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

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

相关问题 如何将adb shell命令结果添加到变量并在if语句中使用它 - how to add adb shell command result to an variable and use it in if statement 尝试运行 AVD 时“找不到 ADB” - 路径中的 adb.exe,重新安装了平台工具,并且没有安装防病毒软件 - 'unable to locate ADB' when trying to run AVD - adb.exe in path, platform-tools reinstalled, and no antivirus installed CYGWIN上的ADB(可能是路径?) - ADB on CYGWIN (path maybe?) 无法在El capitan OSX中使用ADB - Unable to use ADB in El capitan OSX 亚行无法在bash中使用变量 - adb not working with variable in bash 找不到ADB。 请使用Android SDK根目录路径设置ANDROID_HOME环境变量 - Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path 找不到 adb 请使用 Android SDK 根目录路径设置 ANDROID_HOME 环境变量 - Could not find adb Please set the ANDROID_HOME environment variable with the Android SDK root directory path 我正在尝试将变量从shell脚本传递给adb shell命令 - I am trying to pass a variable from shell script to adb shell command 尝试向sdcard添加路径时出现Nullpointer异常 - Nullpointer exception when trying to add path to sdcard 在adb命令中添加空间 - Add space in adb command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM