Related
while running cordova build from my app directory i get following error
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /home/shakir/Documents/myapp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/shakir/Documents/myapp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
I have set my ~/.profile file as follows
export ANDROID_HOME="/usr/local/android-sdk-linux"
export ANDROID_PLATFORM_TOOLS="/usr/local/android-sdk-linux/platform-tools"
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_PLATFORM_TOOLS
and echo ANDROID_HOME give following results
/usr/local/android-sdk-linux
I am using Ubuntu 14.04. How to solve this issue and build cordova apps?
This error occurs, because of you didn't set your android sdk path correctly.
First, find where the android-sdk folder located in your computer. Inside the android-sdk folder, there is a folder called 'platform-tools'. So you can identify android-sdk folder correctly. Then get the path to the android-sdk folder. Now open the terminal and enter following command,
export ANDROID_HOME="your android-sdk path"
Now run the project.
you have probably used "sudo" for adding android platform.. a quick solution for this problem is:
Restore the right folder permission to all the folder/subfolder of the platforms folder
Delete the android platform with sudo cordova platform remove android
Add the android platform with cordova platform add android DON'T USE THE SUDO! If there are errors without the sudo SO that's the problem! NEVER use the sudo thing or the project will have issue like this!
if you still have a problem then you may have installed cordova using sudo, also there is a solution for it:
first we have to set up npm for global installation so we can use it without sudo, the preferred way of enabling npm to install packages globally without breaking out of $HOME is to set a local node prefix. This is as easy as running:
echo prefix = ~/.node >> ~/.npmrc
echo 'export PATH=$HOME/.node/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
then Running:
npm install -g cordova
it may results in:
Error: EACCES, permission denied '/home/yourusername/.config/configstore/update-notifier-cordova.json'
to fix it:
sudo chown yourusername:yourusername /home/yourusername/.config/configstore/update-notifier-cordova.json
After that, you can happily run npm install -g cordova without sudo, without running into permission conflicts and if something is completely broken and you want to start from scratch, all you need to do is remove your ~/.node directory.
Hope this help!
you can also look at these two links: source 1&2
Run following command in terminal :
export
PATH=${PATH}:/Users/Document/Android-sdk/tools:/Users/Documents/Android-sdk/platform-tools
You may also get this Error
Error: EACCES: permission denied, open '/home/yourusername/.cordova/lib/npm_cache/cordova-android/5.1.1/package/.npmignore'
to fix it use this command
sudo chown -R yourusername:yourusername /home/{username}/.cordova/lib/npm_cache/cordova-android/5.1.1/package
When I run ionic build android command in root of ionic project, I am getting this error:
FAILURE: Build failed with an exception.
Where: Script '/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle'
line: 64
What went wrong: A problem occurred evaluating root project 'android'.
No installed build tools found. Please install the Android build tools version 19.1.0 or higher.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
javad#javad:~/Desktop/javadApp$ ionic build android
Running command: /home/javad/Desktop/javadApp/hooks/after_prepare/010_add_platform_class.js /home/javad/Desktop/javadApp
add to body class: platform-android
Running command: /home/javad/Desktop/javadApp/platforms/android/cordova/build
ANDROID_HOME=/opt/android-sdk
JAVA_HOME=/usr/lib/jvm/default-java
Running: /home/javad/Desktop/javadApp/platforms/android/gradlew cdvBuildDebug -b /home/javad/Desktop/javadApp/platforms/android/build.gradle -Dorg.gradle.daemon=true
FAILURE: Build failed with an exception.
* Where:
Script '/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle' line: 64
* What went wrong:
A problem occurred evaluating root project 'android'.
> No installed build tools found. Please install the Android build tools version 19.1.0 or higher.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.564 secs
/home/javad/Desktop/javadApp/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /home/javad/Desktop/javadApp/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/javad/Desktop/javadApp/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /home/javad/Desktop/javadApp/platforms/android/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: /home/javad/Desktop/javadApp/platforms/android/cordova/build: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
in ~/.profile i have:
export PATH=$PATH:/opt/android-sdk/tools
export PATH=$PATH:/opt/android-sdk/platform-tools
export PATH=$PATH:/opt/node/bin
export JAVA_HOME=/usr/lib/jvm/default-java
export ANDROID_HOME=/opt/android-sdk
$PATH is:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin
Important issue:
in file:
/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle | line 38:
String[] getAvailableBuildTools() {
def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
buildToolsDir.list()
.findAll { it ==~ /[0-9.]+/ }
.sort { a, b -> compareVersions(b, a) }
}
just returned /opt/android-sdk/build-tools !!!
in /opt/android-sdk/build-tools folder i have:
android-5.1 folder that extract from:
https://dl.google.com/android/repository/build-tools_r22-linux.zip
I fix this by downloading sdk package called platform-tools and buid-tools using sdkmanager. You can use sdkmanager.exe or if you are using SDK CLI, go to ~\AppData\Local\Android\sdk\tools\bin and run this command:
sdkmanager "platform-tools" "platforms;android-26"
or
sdkmanager "build-tools;27.0.3"
or both
After that you should be able to run ionic cordova run android or ionic build android.
Note: globalize sdkmanager command by adding ~\AppData\Local\Android\sdk\tools and ~\AppData\Local\Android\sdk\tools\bin to your environment variable.
For me running these three commands fix the issue on my Mac:
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
For ease of copying here's one-liner
export ANDROID_HOME=~/Library/Android/sdk && export PATH=${PATH}:${ANDROID_HOME}/tools && export PATH=${PATH}:${ANDROID_HOME}/platform-tools && export ANDROID_SDK_ROOT=~/Library/Android/sdk
To add Permanently
Follow these steps:
Open the .bash_profile file in your home directory (for example, /Users/your-user-name/.bash_profile) in a text editor.
Add export PATH="The above exports here" to the last line of the file, where your-dir is the directory you want to add.
Save the .bash_profile or .zshrc file.
Restart your terminal. Or run source ~/.bash_profile or source ~/.zshrc depending on your terminal settings.
Adding to bash process for different systems
You are missing android SDK tools. Please try the following:
android list sdk --all
android update sdk -u -a -t <package no.>
Where <package no.> is 1,2,3,n and
-u (--no-ui) # Headless mode
-a (--all) # Includes all packages (also obsolete ones)
-t (--filter) # Filter by package index
as the error says 'No installed build tools found'
it means that
1 : It really really really did not found build tools
2 : To make him find build tools you need to define these paths correctly
export ANDROID_HOME=/Users/vijay/Software/android-sdk-macosx
export PATH=${PATH}:/Users/vijay/Software/android-sdk-macosx/tools
export PATH=${PATH}:/Users/vijay/Software/android-sdk-macosx/platform-tools
3 : IMPORTANT IMPORTANT as soon as you set environmental variables you need to reload evnironmental variables.
//For ubuntu
$source .bashrc
//For macos
$source .bash_profile
4 : Then check in terminal
$printenv ANDROID_HOME
$printenv PATH
Note : if you did not find your changes in printenv then restart the pc and try again printenv PATH, printenv ANDROID_HOME .There is also command to reload environmental variables .
4 : then open terminal and write HALF TEXT '$and' and hit tab. On hitting tab you should see full '$android' name.this verifys all paths are correct
5 : write $android in terminal and hit enter
Please install the Android build tools version 19.1.0 or higher.
The following commands can update Android SDK on Ubuntu quickly and fix the above error:
android list sdk --all
android update sdk -u -a -t 19
android update sdk -u -a -t 20
I fix the error by changing the ANDROID_HOME to
C:\Users\Gebru\AppData\Local\Android\Sdk from wrong previous directory.
I know this doesn't look related, especially given the error message, but I fixed this by installing a newer version of the Android SDK Build tools.
2018
The "android" command is deprecated.
try
sdkmanager "build-tools;27.0.3"
This work for me, as #Fadhil said
In my case, the Enviroument Variable ANDROID_HOME was pointed to wrong (old) directory. I reallocated to correct one. In my case
ANDROID_HOME=F:\Program Files (x86)\Android\android-sdk
For me, the problem was that ANDROID_HOME was pointing to an old Android SDK path. After installing Android Studio, I had to update ~/.bash_profile accordingly for MAC (El Capitan)
export ANDROID_HOME="/Users/corneliusparkin/Library/Android/sdk"
Remember to re-start terminal or run this command after updating ~/.bash_profile
source ~/.bash_profile
FOR WINDOW: I have faced this type of issue. But after exploring it solved in my case. I am using window 10. just follow few steps below:
download Android SKD Manager for windows. https://developer.android.com/studio at the
end of this page. It is zip file. after extracting it will show tools directory.
Go to drive C:\ create new folder 'android-sdk'. copy tools folder and past in
C:\android-sdk
open command prompt as Administrator. Go to cd " c:\android-sdk\tools\bin ".
sdkmanager will be show here. type
skdmanager, it will show like this
[=======================================] 100% Computing updates...
after that type "sdkmanager platform-tools" it will create platform-tools directory
in C:\android-sdk
Now set System environment variables: right click on PC select
properties. system settings will popup. click on > Environment Variables. Environment
Variables will popup.
At this window System variables as like this. C:\android-sdk\platform-tools and
C:\android-sdk\tools\bin
run command to build tools sdkmanager "build-tools;27.0.3"
Also make sure java path is defined. I hope it will solve problem.
Type android on your command line and install "Android SDK Build-tools"
I Search this problem for days.... I hope it will be usefull
FINAL SOLUTION:
(I assume that you have installed Oracle-JDK and ANDROID)
open /etc/environment with
sudo nano /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/shoniisra/Android/Sdk/tools:/home/shoniisra/Android/Sdk/platform-tools:/home/shoniisra/Android/Sdk/build-tools:/home/shoniisra/Android/Sdk:/home/shoniisra/android-studio/bin"
JAVA_HOME="/home/shoniisra/java/jdk1.8.0_231"
ANDROID_HOME="/home/shoniisra/Android/Sdk/build-tools/29.0.2"
ANDROID_SDK_ROOT="/home/shoniisra/Android/Sdk"
ANT_HOME="/home/shoniisra/ant/apache-ant-1.9.14"
Save and exit (CTRL+o CTRL+X)
Reload file source /etc/environment
If you recently installed Android you should accept some licences
cd ~/Android/Sdk/tools/bin/
Execute sdkmanager:
./sdkmanager --licenses
Then Accept all, and Finally generate your APK
cd {yourproyect}
sudo ionic cordova build android
I have solved this issue by following steps:
Go to cordova.gradle file
(platform/android/cordovaLib/cordova.gradle)
Search for getAndroidSdkDir() method
Now simply replace System.getenv("ANDROID_HOME") with your real Android SDK path
In build.gradle script it checks if build-tools version is lower than maxVersion from Gradle configuration.
So in my case, I had environment SDK vars set, but my version was higher than allowed.
def highestBuildToolsVersion = buildToolsDirContents
.collect { new Version(it) }
// Invalid inputs will be handled as 0.0.0
.findAll { it.isHigherThan('0.0.0') && it.isLowerThan(maxVersion) }
.max()
In my case the problem was that ANDROID_HOME was pointing to ~/Library/Android/ for some reason.
The correct path is ~/Library/Android/sdk
This problem I solved with the following detail, somehow the android SDK manage installed all the dependencies and necessary files, but forget this `templates` files where is found templates> gradle> wrapper. This set of files is missing.
Path in mac
/Users/giogio/Library/Android/sdk/tools/templates
I had the same problem. I tried all the solutions on this page, but what worked for me was installing the EXACT version of build-tools requested. In my case, I had a later version installed(33.0.0), but in order to make it work I had to download an older one 30.0.3.
This works for me! be careful with the new java versions because they cause error, check that you have everything installed and in your specific directory,
I did not use openJDK
export JAVA_HOME="/usr/lib/jvm/java-8-jdk" \
&& export PATH=$JAVA_HOME/bin:$PATH \
&& export ANDROID_HOME=$HOME/Android/Sdk \
&& export PATH=${PATH}:${ANDROID_HOME}/tools \
&& export PATH=${PATH}:${ANDROID_HOME}/platform-tools \
&& export GRADLE_HOME=/usr/share/java/gradle/bin/gradle \
export PATH=$PATH:$GRADLE_HOME/bin
Linux 4.14.39-1-MANJARO #1 SMP PREEMPT Wed May 2 19:03:39 UTC 2018 x86_64 GNU/Linux
I added <preference name="android-minSdkVersion" value="19" />
to my conf.xml and the build was successful.
The solution for this question is here
https://docops.ca.com/devtest-solutions/8-0-2/en/installing/setting-up-the-mobile-testing-environment/preinstallation-steps-for-mobile-testing/
Please follow this steps, and solve your problem.
The Android SDK package contains a component called compile tools. The mobile test requires at least version 19.0.1, 19.1.0 or 20.0.0.
If these versions are not installed with your ADT package, you may receive an error message when creating a mobile asset in the DevTest Workstation:
Mac IOS
Edit ~/.bash_profile by using vi or other shell editor
vi ~/.bash_profile
Add the following lines:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:~/Software/android-sdk-macosx/tools:~/Software/android-sdk-macosx/platform-tools"
(save the file, and exit)
load those updated env variables to the current shell env:
. ~/.bash_profile
If from some reason you have an old version of the build tools, you can update them from the android development studio:
Configure --> SDK Manager --> select "Android SDK Build-Tools
Check the "Show Package details"
review the versions of this package, update if needed
Well Many people give their answer, some answer is same, some answer id different. I try many answer but they are did not work for me, of course I try from above answer also but did not solve my issue. And I don't know why but I have the same error even my issue solved by this ANSWER. I just want to write it might be helpful for someone.
I have tried all the above solution. None works.
Until I was linked to https://forum.ionicframework.com/t/ionic-v4-no-installed-build-tools-found/152150.
Apparently, you must run the command as root. Sudo is not enough. You need to change to root user before you can run all the commands.
Open Command Prompt Check for ANDROID_HOME path using SET ANDROID_HOME, if not set then set using below command.
SET ANDROID_HOME="C:\Users\VenkateshMogili\AppData\Local\Android\Sdk"
OR
open system environment variables and create new variable as
Variable Name: ANDROID_HOME
Variable Value: C:\Users\VenkateshMogili\AppData\Local\Android\Sdk
and open cordova.gradle file (/platforms/android/CordovaLib/cordova.gradle) and search for getAndroidSdkDir() method and Replace the ANDROID_HOME path ("C:/Users/VenkateshMogili/AppData/Local/Android/Sdk") instead of System.getenv("ANDROID_HOME")
If license problem arises then type below command by opening the command prompt in C:\Users\VenkateshMogili\AppData\Local\Android\Sdk\tools\bin
sdkmanager "build-tools;27.0.3" //<-that will create build-tools folder and licenses folder.
It works for me.
Warning for developers using Virtual Machines
I spent a very long time trying to resolve this issue. I tried everything in this post and many more solutions on the web. However, after many failures and going through what everyone on the web was saying I still couldn't resolve the issue on my VM - which is a Windows 10 image on VMWare Workstation.
After reviewing all the solutions and descriptions of machines/operating systems people were developing on the glaring difference in my setup was I was developing in a VM.
Solution: I pulled all my code onto the host machine (Windows 10 OS), reinstalled all the dependencies, and sure as heck it all worked out first go around. After a lot of research I found some warnings that Android Studio has some known issues around installing properly in some VMs. So if you were like me & tried all solutions (many times over) and nothing worked, but you're in a VM, you may need to consider building on your host (or other physical machine)
This issue also occur if you do an upgrade to you cordova installation.
Check if your log error has something like:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting) <-------------
ANDROID_HOME=/{path}/android-sdk-linux (DEPRECATED)
Using Android SDK: /usr/lib/android-sdk
Starting a Gradle Daemon (subsequent builds will be faster)
In such case, just change ANDROID_HOME to ANDROID_SDK_ROOT in your ~/.bashrc
or similar config file.
Where before was:
export ANDROID_HOME="/{path}/android-sdk-linux"
Now is:
export ANDROID_SDK_ROOT="/{path}/android-sdk-linux"
Don't forget source it: $ . ~/.bashrc after edition.
Check whether you have added android SDK paths to the environment file (.bash_profile). If you installed android studio with default path, then add the below lines to your environment file. In my case, I am using bash so I have updated the .bash_profile
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
I wasted a day to resolve this issue and finally I got solution
-First I removed ionic cordova platform android
-Install ionic cordova platform android#8
That's it
create a ~/.bash_profile and ~/.zshrc file.
touch ~/.bash_profile;
touch ~/.zshrc;
edit and copy/paste this in your ~/.bash_profile or ~/.zshrc file
So, go to your file manager and show all hidden files by using Cmd+Shift+. or Cmd+>
i) Edit your .zshrc file
export LANG=en_US.UTF-8
export ANDROID_HOME=/Users/bookwarm/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/sdkmanager
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/platform-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/build-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/bin
export ANDROID_NDK=/Users/{your name}/Library/Android/sdk/ndk-bundle
export JAVA_HOME=$(/usr/libexec/java_home)
ii) Edit your .bash_profile file
export ANDROID_HOME=/Users/{your name}/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/sdkmanager
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/platform-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/build-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/bin
export ANDROID_NDK=/Users/{your name}/Library/Android/sdk/ndk-bundle
export JAVA_HOME=$(/usr/libexec/java_home)
Save your file with file->save like you would save any regular file, after that write this in your terminal
source ~/.bash_profile;
source ~/.zshrc;
Close you terminal and run your command now
I'm triying to build my first cordova project, when I'm inside the project folder i tip:
sudo cordova build android
and I get the following error:
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/veritopsecret/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
when I do echo $PATH I get:
veritopsecret#veritopsecret-SATELLITE-PRO-C50-A-1HQ:~/hello$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/veritopsecret/Escriptori/android-sdk-linux/tools:/home/veritopsecret/Escriptori/android-sdk-linux/platform-tools
I have also modified .profile file, but it stills say that it hasn't android command in the PATH. However, if I just write android, it opens the android sdk manager. Help please!!
As I re-read your question, I see you run sudo cordova build android
I think the issue you have is that you define ANDROID_HOME and add the android tools to the path of your user but then you use sudo to run the build.
sudo runs with elevated privileges using a user which is not your user profile that you are logged with, so the path and ANDROID_HOME are not set. (maybe try sudo echo $PATH to be sure of that).
So if you really wanted to use sudo to build, you would need either to define the vars for the sudo user or use instead sudo -E (see this page for more details : https://wiki.archlinux.org/index.php/Sudo#Environment_variables)
But actually, you should be using sudo only when installing cordova, not when using the CLI.
So, just run cordova build android and everything should be fine.
UPDATE 1:
This was everything I did in the end:
sudo aptitude install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo aptitude update
sudo aptitude install nodejs
sudo aptitude install npm
sudo npm install -g cordova
sudo npm install -g phonegap
phonegap create my-app
cd my-app
export PATH=${PATH}:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/platform-tools:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/tools
sudo aptitude install ant
cordova platform add android
android create avd --name my_and --target 1
phonegap run android
Was any of that not neccessary?
ORIGINAL QUESTION:
On my Ubuntu 12.04 computer, I've just installed node.js with npm and cordova:
$ node -v
v0.10.23
$ npm -v
1.3.17
$ cordova -v
3.3.0-0.1.1
When I try to add android:
$ cordova platform add android
I get the following output:
Creating android project...
/usr/lib/node_modules/cordova/node_modules/q/q.js:126
throw e;
^
Error: An error occured during creation of android sub-project.
/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29
at _rejected (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:808:24)
at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:752:41)
at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:574:44
at flush (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
at /usr/lib/node_modules/cordova/src/platform.js:244:30
at ChildProcess.exithandler (child_process.js:641:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:735:16)
at Socket.<anonymous> (child_process.js:948:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:466:12)
Anyone know why this is happening and how to resolve it?
I get the same issue with PhoneGap.
It's possible that the Android tools binaries are not in your path.
According to the PhoneGap docs (http://docs.phonegap.com/en/2.9.0/guide_getting-started_android_index.md.html), you need to include the Android SDK's tools and platform-tools in your PATH environment variable.
export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools
where Development is the path you installed your SDK.
Run the "android" command from your adt\sdk\tools folder and install the latest Tools and SDK. Also make sure your PATH has the right variables.
For this you will need ANT to be installed , a JAVA JDK and an Android SDK installed
JAVA_HOME (C:\Program Files\Java\jdk)
ANT_HOME ({ant location}\apache\apache-ant)
ANDROID_HOME ({android sdk location}\android-sdk)
Add these to your PATH variable like %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
Close and re-open your cmd and run your command again.
I'm running Ubuntu 12.04 and was having the same problem as you until a few minutes ago.
The two things I've noted that I had missed during installation:
The Android version should be 19 and you should be able to type 'android' at the console and see some output or see a window pop-up. Make sure that you add the path to the folder where android.jar is located to your PATH variable, and set ANDROID_HOME to that same path as well. Typically, you would do this in your .bashrc file or in /etc/environment If you edit either of these files, you'll need to either 'source ~/.bashrc' or reopen your terminal to force it to reload the file. Type 'android' to make sure its working.
I observed that the cordova setup script was attempting to write files into a subdirectory 'add-ons' of the Android SDK. That directory does not exist in the Android 19 distribution itself. Consequently, I created it manually and made it writeable by my user account.
ex: Android distribution path:
/opt/android/
The path that its trying to write to:
/opt/android/sdk/add-ons
Once I had done that I was able to get past the problem you've noted above.
It looks like the cordova andorid library file corrupted in your home directory.
Try to remove home//.cordova directory and do this again cordova platform add android in your cordova project.
Make sure you have sourced /platform-tools and /tools to PATH.
Android
The Android command-line tools are built upon shell scripts. You must have the Android SDK's tools and platform-tools folders in your PATH!
Create a project
Run the create command with the following parameters:
Path to your new Cordova Android project
Package name, following reverse-domain style convention
Main Activity name
$ /path/to/cordova-android/bin/create /path/to/my_new_cordova_project com.example.cordova_project_name CordovaProjectName
It looks like this error could also be caused by the absence of a compatible Android SDK version (at the moment 4.2).
I use cordova.
2days I have same problem"java,ant,android,cordova,command test is ok,
but run cordova platform add android show me Error: An error occurred while listing Android targets".
Now I fixit use:
"chmod 777 ant and android sdk place"
,then it will work.
I use ubuntu 14.04 32bit,
if the problem still exist please make sure that you have the right permissions try
sudo chmo-R 777 /home/your-user-name/.cordova/
Also make sure that you are NOT using sudo to add Android as a platform
This is incorrect in the default Cordova installation
sudo cordova platform add android
Just do
cordova platform add android
I've searched a lot for this, and what worked for me was setting the shell variable $ANDROID_HOME to the path of the sdk/ folder in my adt-bundle directory from android. Use export to do this:
export ANDROID_HOME="/Users/YOUR_USER/Developer/adt-bundle/sdk/"
but be sure to change the directory to match yours.
Good Luck!
Not sure if someone else had a problem with this, but when removed and added my platform again, I realized in my config.xml I had <icon src='...'> and the path inside the src was wrong.
Here was the error output I received when I added the platform again:cp: no such file or directory: C:\Users\{pathtofile}.png.
After I fixed the path, it worked fine.
It can be that your cordova installation have been corrupted try to remove your .cordova folder "rm -R ~/.cordova"
And "run cordova platform add android" again
edit: (aug-2016)
That question is from November 2013 (while Android Studio was still in Developer Preview mode),
Currently (AS v2.2, Aug-2016) during instalation AS asks to choose the SDK folder (or install on their default) and it automatically applies to which ever project you're opening.
That means any possible workaround or fix is irrelevant as the issue is not reproducible anymore.
original question:
we have this project with several modules that is already configured and executes correctly on another developer PC using a wrapper. I cloned the complete git submodules into my machine.
Below it's a directly print of my command line:
$ ./gradlew
FAILURE: Build failed with an exception.
* Where:
Build file '/home/budius/project_name/ActionBar-PullToRefresh/library/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':ActionBar-PullToRefresh:library'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 6.378 secs
$ echo $ANDROID_HOME
/home/budius/Applications/android-studio/sdk
$
so, as you can see the ANDROID_HOME is there. What else do they want? What's wrong here.
running on Ubuntu 13.04
edit:
I already created a local.properties file with sdk.dir=<path> on the project root and it works. But that makes the code harder to port across systems n build server, so the question is still open.
Anyone knows why the ANDROID_HOME is not working and what to do to make it work?
In /my_current_project/, I created a file called local.properties and put inside:
sdk.dir=/my_current_path_to/sdk
In the console I need to do:
set ANDROID_HOME=/my_current_path_to/sdk
On OSX, IntelliJ won't pick up the environment variables you set in your .bash_profile or .bash_rc etc...
Try this, substituting the value of your own sdk location:
launchctl setenv ANDROID_HOME /usr/local/opt/android-sdk
Then restart IntelliJ and Bob's your uncle.
Here is a reference to the problem, stated more generally:
https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/
In my case settings.gradle was missing.
Save the file and put it at the top level folder in your project, even you can copy from another project too.
Screenshot reference:
Hope this would save your time.
This works for me:
$ export ANDROID_HOME=/path_to_sdk/
$ ./gradlew
The Android Gradle plugin is still in beta and this may simply be a bug. For me, setting ANDROID_HOME works, but we may be on different versions (please try again with the most recent version and let me know if it works or not).
It's also worth setting the environment variable ANDROID_SDK as well as ANDROID_HOME.
I have seen issues with this on some machines, so we do create local.properties in those cases - I have also noticed that the latest version of Android Studio will create this file for you and fill in the sdk.dir property.
Note that you shouldn't check local.properties into version control, we have added it to our gitignore so that it doesn't interfere with porting the code across systems which you rightfully identified as a potential problem.
For whatever reason, the gradle script is not picking up the value of ANDROID_HOME from the environment. Try specifying it on the command line explicitly
$ ANDROID_HOME=<sdk location> ./gradlew
I faced the same issue, though I had local.properties file in my main module, and ANDROID_HOME environment variable set at system level.
What fixed this problem was when I copied the local.properties file which was in my main project module to the root of the whole project (i.e the directory parent to your main module)
Try copying the local.properties file inside modules and the root directory. Should work.
I came across the same problem when opening a cloned git repository. The local.properties file is automatically added to the .gitignore file as it is specific to the build environment of each machine and is therefore not part of the repo.
The solution is to import the project instead of just opening it after you have cloned it from git, this forces android studio to create the local.properties file specific to your machine:
File >> Import Project >>
MAC OSX:
Open up Terminal and edit the file:
~/.bash_profile
to add:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
Run:
source ~/.bash_profile
Restart the Terminal and Android Studio
How to do it on MAC OSX:
1) Open up Terminal, and Edit: vi ~/.bash_profile If there is no file there, just add it.
2) Add (Change to YOUR USER NAME and add this):
#Java var home:
JAVA_HOME="/usr/libexec/java_home"
ANDROID_HOME="/Users/<YOUR USER NAME>/Library/Android/sdk"
3) Run source ~/.bash_profile.
4) Run echo $JAVA_HOME; echo $ANDROID_HOME;
5) If your output is:
/usr/libexec/java_home
/Users/<YOUR USER NAME>/Library/Android/sdk
So you are good.
and RESTART android studio!
And,
Make sure that you have java :)
java -version
And gradle :)
gradle --version
Copy the local.properties to root folder and run again.
This worked for me (Ubuntu):
Add ANDROID_HOME=/path/to/android-sdk to /etc/environment.
Reboot.
in windows, I set ANDROID_HOME=E:\android\adt-bundle-windows-x86_64-20131030\sdk
Then it works as expect.
When in Linux, you need to set sdk.dir.
The script uses two different variables.
I have the same problem, seems the sample code can not find the android environment, instead to try to fix that I just remove the sample code from settings.gradle and then the installation goes fine.
after that just import the project in eclipse and that's all :)
In Linux, try to run studio.sh from a terminal and set the ANDROID_HOME in this terminal. This worked for me.
If you are using windows plantform, please try run Android Studio as Administrator
Just delete the sdk.dir inside the local.preoperties file and set the ANDROID_HOME environment variable . It worked for me.
export ANDROID_HOME=/xxx/xxx/ in shell, then use it by System.env.ANDROID_HOME in gradle file.
PS: don't forget the 'export' keywords to make the ANDROID_HOME global.
Your local.properties file might be missing. If so add a file named 'local.properties' inside /local.properties and provide the sdk location as following.
sdk.dir=C:\Users\\AppData\Local\Android\Sdk
I have set the ANDROID_HOME = [PATH_OF_MY_ANDROID_SDK] to my environment variable. That solution works for me.
I have just solved the exact same issue by adding the ANDROID_HOME as a system wide variable.
In Ubuntu it should be in /etc/profile or in a shell script file in /etc/profile.d/
Then logout and login again, now Gradle should recognize the ANDROID_HOME variable.
I came across a similar problem. Somehow, I did not have a build folder in my project. By copying this folder from another project to my project I was having an issue with, this fixed this problem.
Installing Build-Tools 23.0.1 instead of 23.0.2 fixed this issue for me.
solutions:
1 add "sdk.dir=path_of_sdk"
2 execute gradlew with evn variable like following:
$ANDROID_HOME=path_of_sdk ./gradlw
You said that versioning local.properties creates problems for you. I've hacked together a script which uses android command line tool to refresh the local.properties file across the machines that are involved in the production. The android update project command, besides the local.properties produces a lot of unwanted trash (at least for me) which is the reason for all those rm commands at the end of the script.
#!/bin/bash
scname="$0"
echo "${scname}: updating local properties..."
ln -fs src/main/AndroidManifest.xml
android update project -t 24 -p "$(pwd)"
echo "${scname}: ...done"
echo "${scname}: removing android update project junk ..."
rm -v project.properties
rm -v build.xml
rm -v proguard-project.txt
rm -v AndroidManifest.xml
echo "${scname}: ...done"
This script is the first thing we run on any new machine where we code. It has to be run in the root project directory. Of course, android studio may have a GUI way of dealing with this, but I wouldn't know as I use a different editor. I also can't claim that the solution is general, but it "Works For Me" (tm).
I have faced with the same issue on Ubuntu(both local.properties and ANDROID_HOME was added), but build fail persisted. So workaround is to
add following lines
export ANDROID_HOME=/home/<user>/Android/Sdk
export PATH=$PATH:/home/<user>/Android/Sdk/tools
directly to the studio.sh script (inside /usr/local/android-studio/bin)
Maybe it will be helpful.
i encountered the same error but in my case i was cloning a project, the cloned project was built with Android API 22 which i did not install at the time(i had API 24 and 25 installed)........so i had to download the sdk tools for API 22
For Windows:
Add ANDROID_HOME to the Environment Variables:
ANDROID_HOME = C:/Users/YOUR_USERNAME/AppData/Local/Android/sdk
Add %ANDROID_HOME%\platform-tools to the PATH.
On my system (Ubuntu 20.04 after two version upgrades from 19.04) the symptoms were as if gradle (4.4.1 installed from APT repos) ignored ANDROID_HOME environment variable, while picking up the sdk.dir value from local.properties if I created one.
The reason appeared to have been that java command referred to openjdk version "11.0.7". After I installed openjdk-8-jdk package and did update-alternatives --config java to make the default java be version 8 ("1.8.0_252"), gradle started working as expected.
My issue was that directory did not exist. The env vars were set correctly, but the underlying directory did not exist. After opening AS the first time and having it create the directory, everything worked.
echo $ANDROID_HOME
/Users/x/Library/Android/sdk
$ echo $ANDROID_SDK_ROOT
/Users/x/Library/Android/sdk
$ cd $ANDROID_HOME
-bash: cd: /Users/x/Library/Android/sdk: No such file or directory