2

In my new MacBook, I installed latest Android Studio. Then, in terminal, I created the .bash_profile, and added 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 command source .bash_profile, then I type adb command, but get error that adb is not recognized as a command. Why? I also echo $PATH, I saw the platform_tools directory of Android sdk is there & there is adb file under that directory.

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

It is interesting, if I do following, 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 ~ above identical to /Users/myname? Why my original script doesn't work but the above one works? I don't understand....Please someone explain to me.

Alex P.
  • 27,029
  • 16
  • 103
  • 156
Leem.fin
  • 35,699
  • 70
  • 166
  • 297
  • 2
    Please post the output of `find ~ -name 'adb*'`. Also, you should export `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT`. [According to the NDK team](https://groups.google.com/forum/#!msg/android-ndk/qZjhOaynHXc/2ux2ZZdxy2MJ), the Android tools use the variables to find things. There's also a `ANDROID_SDK_HOME` discussed in some questions, but its not documented. I still have not seen a canonical reference for it. Finally, `ANDROID_HOME` looks incorrect. Usually its something like `~/.android`. It does not point to the SDK directory. – jww Jun 22 '17 at 21:28
  • Check out [this](https://stackoverflow.com/questions/31374085/installing-adb-on-mac-os-x) link, you can use brew to install the adb... No hassle.. – Harish Talanki Jun 22 '17 at 21:30
  • @jww, I have added ndk and sdk path. I can see adb executable under my `ANDROID_HOME/platform_tools`, I don't understand what does `Usually its something ~/.android` mean. – Leem.fin Jun 23 '17 at 20:32
  • 1
    Also worth mentioning... Bash has a "program path cache" that sometimes needs updating. Its the reason for problems like [Path not being honored?](https://apple.stackexchange.com/q/226149/83961) on [Apple Stack Exchange](http://apple.stackexchange.com/). Its a Bash issue; not an OS X issue. – jww Jun 23 '17 at 20:45
  • 3
    typographical error - `platform_tools` vs `platform-tools` – Alex P. Jul 08 '17 at 21:17
  • 1
    Hey @AlexP. Post your solution and get the 50 points. They belong to you. – G. Blake Meike Jul 09 '17 at 17:09
  • 1
    @G.BlakeMeike, I do not care about the points. If that's indeed the only cause of OP's problem - the question would be off-topic and should be closed. – Alex P. Jul 09 '17 at 17:15
  • well, you get my vote. well done. – G. Blake Meike Jul 09 '17 at 17:29
  • Change to the folder that contains adb and do an ls -ll on the folder. Check the execute attributes are set appropriately. Also use ${HOME} instead of ~ in path. And as others have mentioned the _ vs - is a problem! – JGFMK Jul 11 '17 at 19:01
  • have you tried to add these exports in `.profile` file?? – ELITE Jul 14 '17 at 16:47

3 Answers3

3

Depending on the shell, export variable definitions can be treated differently than normal assignments — in particular, tilde expansion might not occur at all.

If this is the case, then every unresolved tilde in a variable stays unresolved even if this variable gets expanded somewhere else. According to the docs:

The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, <…>

You might want to try this:

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 it doesn`t help, you can also try $HOME:

ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_HOME
hidefromkgb
  • 5,396
  • 1
  • 11
  • 39
1

This pretty fundamental stuff:
In the current directory (./) execute command "adb"
./adb (you say this works).
what you want is adb (execute command adb found from the PATH variable), if the command "adb" can be found after searching in ALL paths in the PATH variable, execute the command adb where it is found.
A common precursor in the path entries is "." (current directory) but is discouraged due to executable name abuse (same name in a random directory).
Different paths are separated by the path separation variable (in windows it is semicolon ";" UNIX usually colon ":" ALSO MAC). Your multiple exports SEEM to be over writing each other, do it once with the appropriate separator ":" and all your paths in one (or ALWAYS include $PATH: to retain all previous exports).
it should be in ../somewhere../sdk/platform-tools/adb
(where ever your SDK resides) export PATH=$PATH:/Users/myname/Library/Android/sdk/platform-tools seems ok (be careful not to over-ride it[erase]).
After a re-boot all paths should be honored.
NB
in UNIX we have the "which adb" command which tells us where the executable resides. In Windows with tools like cygwin we can also do the same thing.
I believe Mac has Homebrew.

Jon Goodwin
  • 8,580
  • 5
  • 28
  • 52
1

In your example all lines work OK (but pay particular attention to platform_tools folder's name):

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've got a mistake:

platform_tools

instead of:

platform-tools

enter image description here

Also, you could try this solution, it works fine:

# 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
Andy Fedoroff
  • 26,838
  • 8
  • 85
  • 144