"adb" is not recognized as a command

On my new MacBook, I have installed the latest Android Studio. Then, in the terminal, I created a .bash_profile file and added the following lines to the file:

export ANDROID_HOME=~/Library/Android/sdk

export ANDROID_TOOLS=$ANDROID_HOME/tools

export PATH=$PATH:$ANDROID_HOME/platform_tools

export PATH=$PATH:$ANDROID_TOOLS

      

After that I run the command source .bash_profile

, then I type the command adb

, but I get an error that adb is not recognized as a command. What for? I also echo $PATH

, I saw that there is an platform_tools

android sdk directory and there is an adb file in that directory.

====== UPDATE =====

I wonder if I follow, it works:

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

      

Why? Isn't it ~

higher than /Users/myname

? Why is my original script not working but above working? I don't understand ... Please someone explain to me.

+3


source to share


3 answers


Depending on the shell, export

variable definitions can be handled differently than normal assignments - in particular, tildes cannot occur at all.

If so, then any unresolved tilde in a variable remains unresolved, even if that variable expands elsewhere. According to the docs :

Expansion order: parenthesis expansion; tilde expansion, parameter and variable expansion , <...>

You might want to try the following:



ANDROID_HOME=~/Library/Android/sdk
export ANDROID_HOME

export ANDROID_TOOLS=$ANDROID_HOME/tools

export PATH=$PATH:$ANDROID_HOME/platform_tools

export PATH=$PATH:$ANDROID_TOOLS

      

If that doesn't help, you can also try $HOME

:

ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_HOME

      

+3


source


This is pretty fundamental stuff:
In the current directory (./), run the "adb" command
. / adb (you say it works).
what you want is adb (execute adb command found from PATH variable), if "adb" command can be found after searching all paths in PATH variable then run adb command where found.
The common predecessor in a path entry is "." (current directory), but it is discouraged due to an executable filename violation (same name in a random directory).
The different paths are separated by a path separator variable (in windows it is a semicolon), "UNIX usually colon": "ALSO MAC ) Your multiple SEEM exportswill overwrite each other, execute once with the appropriate ":" separator and all your paths in one (or ALWAYS include $ PATH: keep all previous exports).
it should be in .. /somewhere../sdk/platform-tools/adb
(where your SDK is ever stored) export PATH = $ PATH: / Users / myname / Library / Android / sdk / platform-tools looks ok ( be careful not to overload it [wash]).
After reloading, all paths should be completed.
NB
on UNIX we have the "adb" command which tells us where the executable is. On Windows, with tools like cygwin, we can do the same too.
I believe the Mac has Homebrew.



+1


source


In your example, all lines work fine (but pay special attention to the folder name platform_tools

):

export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_TOOLS=$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform_tools:$ANDROID_TOOLS

source .bash_profile
adb

      

enter image description here

So you have an error:

platform_tools

      

instead:

platform-tools

      

enter image description here

Alternatively, you can try this solution, it works great:

# print two export commands to your ~/.bash_profile
echo "export ANDROID_HOME=/Users/swift/Library/Android/sdk" >> ~/.bash_profile
echo "export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools" >> ~/.bash_profile

# Refresh bash profile (or restart Terminal.app)
source ~/.bash_profile

# Start using your adb command
adb --version
adb devices

      

+1


source







All Articles