I have been following these directions to setup android development on a mac. I put the android sdk folder in my desktop folder so my path should be "Desktop/android-sdk-macosx", I followed the steps in the terminal but it keeps on telling me permission denied as seen here.
I went to my home directory as well and did COMMAND+SHIFT+. to show hidden files in order to add to the .bash_profile file in my home folder but couldn't find the .bash_profile there.
Here are some details of my setup that works.
Note I put my sdk folder at home, e.g. ~.
First, open up a terminal and type these commands:
cd ~
ls -a
Here is my session, and what is shows:
If you don't have a .bash_profile, then make one:
touch .bash_profile
Then, enter the command:
emacs .bash_profile
Then, set up your ANDROID_HOME and PATH, here is what mine looks like:
Note that I have the SDK manually downloaded, and I used homebrew for the NDK folder, that is why they are set up different.
Related
I had set the ANDROID_NDK_HOME as /Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b using a mac osx application called Environment Variables.
I had confirmed that it set the path correctly in Terminal
echo $ANDROID_NDK_HOME
But when I run a shell file in a Android Studio project which invokes ndk-build I get the following error
ndk-build: command not found
How to make sure that ndk-build is in your build path ?
How to set ndk-build in my build path ?
Thanks for any help
Well, this is actually not enough to make the system aware of the path. You must add this path to the PATH system variable. In your case, all you have to do is to add the following line to your terminal configuration file (which should be under your home directory, named .bashrc if you kept the default terminal, full path: ~/.bashrc):
export PATH=$PATH:/Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b
What this line does is actually adding the path to your Android NDK directory to the PATH variable. You export a variable named PATH with its current content plus the directory of your NDK.
Step by step:
Go in the home directory
Edit .bashrc
Add the line I showed above
Save, exit, then restart bash (you just have to type bash, then enter)
For mac use this: Open your .bash_profile file with a text editor. .bash_profile is by default found in home directory. Eg /Users/john
the assumption is: you have downloaded the android sdk and ndk to /User/john/Android or you can find the path from Android Studio by going to
Project Structure > SDK Location, pay attention to Android SDK location & Android NDK location
export ANDROID_SDK=/Users/john/Android/sdk
export ANDROID_NDK=/Users/john/Android/sdk/ndk-bundle
export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK"
Then save the above lines to your .bash_profile file. Close it and try typing this on your terminal
ndk-build
if the response is like below, you are good to go
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/Users/john/Android/sdk/ndk-bundle/build/core/build-local.mk:143: *** Android NDK: Aborting . Stop.
The assumption here is you have downloaded your android sdk to /Users/john/Android
In case this helps anyone, I installed the Android NDK using Android Studio on MacOS by following the instructions on the android.com NDK webpage: I selected Tools --> Android --> SDK Manager and then selected NDK. Android Studio then installed the downloaded files under:
/Users/user.name/Library/Android/sdk/
That directory is the same one that is listed on the SDK Manager window inside Android Studio. Underneath that directory is another directory ndk-bundle, which has all the NDK tools.
Thus, I added this to my path:
/Users/user.name/Library/Android/sdk/ndk-bundle/
cd to path you have to set.
Enter in Terminal: echo "export PATH=$PATH:$ANDROID_NDK_HOME" | sudo tee -a /etc/profile
I am MAC OS X Yosemite I have done all the export tutorial to set the android_home but non of it working for me
Making sure ANDROID_HOME is exported and adding the SDK tool directories to PATH should be more than enough to get you going.
Using the terminal
# First, we make sure we have a newline at the end of the .bash_profile
echo >> /Users/abdi/.bash_profile
# We set the ANDROID_HOME value in the .bash_profile
echo "export ANDROID_HOME=/Users/abdi/adt/sdk" >> /Users/abdi/.bash_profile
# We alter the PATH value a bit as well
echo "export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools" >> /Users/abdi/.bash_profile
# We then tell the terminal to update all the things
. /Users/abdi/.bash_profile
Using a GUI (mostly)
You can also open the .bash_profile file in TextEdit using the open -e /Users/abdi/.bash_profile command. If you get some errors about missing files, try running touch /Users/abdi/.bash_profile and retry the open command. In the file that opens, add the following lines at the end.
export ANDROID_HOME=/Users/abdi/adt/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Running . /Users/abdi/.bash_profile as in the terminal version after that should get you fully set up.
First need to set the ANDROID_HOME directory
look into your android-sdk-linux(mac) directory and look for 'android' executable file, generally it will exists under 'tools' directory
so edit your .bashrc from home folder
and add this line down there
export ANDROID_HOME=~/android-sdk-linux
PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Once done, exit your console and run your command again
You could expect an error saying " Please install Android target "android-19" " if it is not set yet.
you may fix that running "android" command and selecting "Android 4.4.2 API 19" to install.
And afterwards, don't forget to give ample permission to directory where the application resides.
I had the same problem. Luckily it is easily fixable. Just follow the next few steps (Command-line from terminal).
Open the bash_profile file using command line arguments with -
vi ~/.bash_profile
OR
It is possible to open bash_profile in TextEdit and make changes there. Use the following command to do this -
open -a "TextEdit" .bash_profile
Check if ANDROID_HOME has been set in this file. If it has been already set, delete it (probably wrong). Also check if PATH in this file has any reference to tools or platform-tools (of the android sdk). You'd be better off deleting these before you start typing the following commands.
Set ANDROID_HOME correctly using the following command
export ANDROID_HOME=/Users/adarsh/android-sdk-macosx
^this is my command because I installed it in that location. Please replace "adarsh" with your username and "android-sdk-manager" with the name of your android sdk folder that you downloaded. Do not copy-paste this command.
For example, if your username is "John" and you the android sdk folder you downloaded and installed is in "Downloads" and you changed your folder name to "sdk", then your command would be -
export ANDROID_HOME=/Users/John/Downloads/sdk
Set PATH with the following command
export PATH=$ANDROID_HOME/tools:$PATH
Refresh your bash_profile to set all the changes we just made by typing the command
source ~/.bash_profile
You should be good to go now and begin developing with ionic!Hope this helps. Cheers.
One source of this problem comes from sudo. If you're sure you've set $ANDROID_HOME correctly then try the following:
sudo visudo
then add
Defaults env_keep += "ANDROID_HOME"
Make sure the env variable you exported is ANDROID_HOME and not android_home (case sensitive).
After you export, test it by typing
> echo $ANDROID_HOME
The result should point to the dir where you installed the SDK.
Last but not least edit your /etc/paths to add dirs $ANDROID_HOME/platform-tools or /Users/abdi/adt/sdk/platform-tools and $ANDROID_HOME/tools or /Users/abdi/adt/sdk/tools to the list. Save file. You might need to edit this file as admin if need be. Close terminal and then Open new terminal. Then type
> echo $PATH
to check if the path is updated.
And then voila, when you type
> which android
you should see the correct path to the binary returned which in your case is /Users/abdi/adt/sdk/tools/android. you should be all set now.
None of the solutions here solved my problem completely. My Node version was little bit old and ionic was giving a warning to upgrade node. After upgrading Node, I had to delete the project and again create the project, then perform all the steps. Hope this helps somebody.
My android command wasn't working and people were saying it was because I didn't have a path setup to it, but I checked my ./bash_profile and it was set up. So someone suggested I run the command chmod 777 android and then I could run ./android sdk from the tools folder. I did this and it worked and I could run commands but instead of using the android command, I had to use ./android. How can I fix this so I can use the android commmand instead of ./android
Please check your PATH variable by echo $PATH, My best guess is, that the android tools path is not included. In my case it is
$HOME/bin/android-sdk-linux/tools
echo $PATH should print something like this
$HOME/android-sdk-linux/tools:$HOME/android-sdk-linux/platform-tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
If the android sdk dirs are missing in PATH and you set it in $HOME/.bash_profile:
. $HOME/.bash_profile
will set the PATH.
Make sure . $HOME/.bash_profile is sourced when opening the shell. Configurations differ with every linux distribution here.
If you've only just installed the android sdk you'll need to source your bash_profile again with the source or dot commands. Alternatively, just close your shell and reopen it.
source ~/.bash_profile
. ~/.bash_profile
Alternatively, if that's not it echo $PATH in a shell and double check there's an entry to the bin folder of the sdk.
I'm testing Android application, and I want to run Robotium test from Terminal on Mac. As I've read I use adb shell am instrument -w com.test.test1/android.test.InstrumentationTestRunner
Terminal says "-bash: adb: command not found".
Probably, I don't see something obvious, but I'm really just studying. What am I missing?
It seems like you don't have your Environment Variables set properly. You need to cd into the directory of your android sdk and then go to platform-tools folder. Once you are in there you will be able to use adb.
here is more information (Goto the part where it talks about environment variables in "Exploring the SDK section"
On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to the tools/ and platform-tools/ directories to it. If you don't see a line setting the path, you can add one:
export PATH=${PATH}:/tools:/platform-tools
On a Mac OS X, look in your home directory for .bash_profile and proceed as for Linux. You can create the .bash_profile if you don't already have one.
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. I have added directories before by for some reason adb does not want to be found. This is very frustrating. Has anyone else had this problem before?
I created a file .profile and added the following to it.
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. Now when I try to run adb I get that it is not found.
-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?
Add to PATH for every login
Total control version:
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
check if adb was set into path
adb version
One liner version
Echo your export command and redirect the output to be appended to .bash_profile file and restart terminal. (have not verified this but should work)
echo "export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
sdk/platform-tools/" >> ~/.bash_profile
Alternative: Install adb the easy way
If you don't want to have to worry about your path or updating adb manually, you can use homebrew instead.
brew cask install android-platform-tools
Why are you trying to run "./adb"? That skips the path variable entirely and only looks for "adb" in the current directory. Try running "adb" instead.
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.
Also note that if you have both .profile and .bash_profile files, only the latter gets executed.
On my Macbook Pro, I've added the export lines to ~/.bash_profile, not .profile.
e.g.
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).
So as #davecaunt and #user1281750 noted but insert the following line to .bash_profile
export PATH=/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools:$PATH
The answer for MAC should be:
Open your bash_profile with the following commands: open ~/.bash_profile
In case base profile file doesn't exist, create a new one with the following command: touch .bash_profile then repeat phase 1.
Add the following line: export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH
Restart your bash window and test by typing 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
adb version
It should be fine now.
I use zsh and Android Studio. I use a variable for my Android SDK path and configure in the file ~/.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:
~/Library/Android/sdk/platform-tools/adb
So it goes like this:
Run Terminal
run adb version and expect an error output
touch ~/.bash_profile
open ~/.bash_profile
add the above path before the 'closing' :$PATH
source ~/.bash_profile
run adb version and expect an output
Good luck!
It appears that you're still trying to execute adb with ./adb. That asks the shell to run the program named adb in the current working directory.
Try just adb without ./.
In order to make the terminal always have the file ~/.bashrc and there put the path you wish to use, by adding:
export PATH=$PATH:/XXX
where XXX is the path that you wish to use.
for adb, here's what i use:
export PATH=$PATH:/home/user/Android/android-sdk-linux_x86/platform-tools/
(where "user" is my user name).
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!
If you are Catalina user follow this
Make sure to be in the Home directory
cd ~
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
touch .zshrc
Open it with the TextEditor
open -e .zshrc
Insert the command below to add ADB as PATH variable (replace username with your own)
export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
Save the file and close the TextEditor app. Back to the Terminal app, insert the following to source the file
source .zshrc
And you’re done! Let’s test if it was successful
adb version
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
I added export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/ into both places .bash_profile and .profile to make sure it works. Still it wasn't working and then I looked at sarnold's tip about restarting terminal and it worked like a charm.
It saved my time of adding every time this into the PATH whenever I had to run adb.
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.
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. Moving it to the top just let it run first.
In bash profile
just add -
export 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.
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.
So first check your default shell:
echo $SHELL
if the output is /bin/bash then you should set path variable in
.bash_profile
If the output is /bin/zsh then you should set path variable in .zshrc
And here is my path variable:
export ANDROID_SDK_ROOT="/Users/aliasjad/Library/Android/sdk"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"