Cordova Android Install On Linux - android

I've been pulling my hair out for the past two days trying to get cordova to detect and install the android platform for a project.
The specific error:
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
Command finished with error code 8
I have scoured the net for solutions. Here is the .bashrc file:
export ANDROID_HOME=~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
export ANDROID_SDK_HOME=~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/tools
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
I get the error when running this command:
sudo cordova platform add android -d
Any help would be appreciated!
More Info:
If I run the "android" command, I get the SDK app startup, so I know that works. Ive also installed the latest builders, tools for the SDK.

After a lot of trial an error, it seems the issue was "sudo" all along. Sometimes it's the simplest things that we overlook.
There were also some unnecessary lines in my export commands. The following is all you need:
export ANDROID_HOME=~/adt-bundle-linux-x86_64-20140702/sdk
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/tools
export PATH=${PATH}:~/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
If you get an error that ANDROID_HOME does not exist, change the location to use the absolute path. ie: /home/user_name/....
My project directory needed to be 777, as well.
Finally, make sure you run the following command:
sudo apt-get install lib32stdc++6
Looks like without it, I get build errors.
Hope this helps anyone else in the future. There definitely was not enough clear answers on the web, before.

Related

Building Ionic app on UBUNTU for Android fails with exit code 2: Failed to find 'ANDROID_HOME'

I am using Ubuntu 14.04 version and im trying to work with ionic.
The error comes when I try to:
$ ionic start todo blank
$ cd todo
$ sudo ionic platform add android
$ sudo ionic build android
And I get the 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/kelvin/Desktop/todo/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/kelvin/Desktop/todo/platforms/android/cordova/build: Command failed with exit code 2
I know there is alot of sites with a answer to this question, but none of them gave me a fix. Or maybe they did, but I didnt understand it. I tried on this site building-ionic-app, but that didnt work either.
I followed this tutorial by Nic Raboy, and its still not working.
Install Android, Cordova, and Ionic Framework in Ubuntu.
So let me explain what I did and maybe that is helpfull to fix my problem:
I started with this guide: Ionic Framework Guide
To install Cordova, make sure you have Node.js installed, then run
Install Node.js
$ sudo apt-get install -y nodejs
$ node -v
v5.0.0
Install Cordova
$ sudo npm install -g cordova
Follow the Cordova platform guides for Android and iOS to make sure you have everything needed for development on those platforms.
Follow the Cordova platform guides for Android
I followed this guilde:
Complete installing guide for android SDK / ADT Bund on Ubuntu
My computer is 64-bit and since im using 14.04.
Step 2: install libgl1-mesa-dev:i386 package.
$ sudo apt-get install libgl1-mesa-dev:i386
Step 3: Install openjdk-6-jdk or better, openjdk-7-jdk
$ sudo apt-get install openjdk-7-jdk
Step 4: Download the Android SDK or the ADT Bundle from here and unzip it to wherever you want.
Then I follow step 4 on techtach Complete Guide
$ wget http://dl.google.com/android/android-sdk_r20-linux.tgz
$ wget http://dl.google.com/android/adt/22.6.2/adt-bundle-linux-x86_64-20140321.zip
Then I unzipped the adt-bundle and copied the folders from SDK -> /home/kelvin/android-sdk-linux/
The folders are: build-tools,extras,platforms,platform-tools,system-images,tools.
Then I executed the following command to install latest android updates
$cd ~/android-sdk-linux/tools
$sudo ./android
And installed
Android SDK Tools (24.0.2)
Android SDK Platform-tools (20)
ANDROID SDK Build-tools (19.0.3)
SDK Platform
ARM EABI V7a System Image
Android Support Library
And then open bashrc
$gedit ~/.bashrc
And added the following lines.
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools
export ANDROID_HOME=~/android-sdk-linux/tools
Checking if it is right:
$ANDROID_HOME
bash: /home/kelvin/android-sdk-linux/tools: Is a directory
Create the project & Configure Platforms
$ ionic start todo blank
$ cd todo
$ sudo ionic platform add android
$ sudo ionic build android
And I get the 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/kelvin/Desktop/todo/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/kelvin/Desktop/todo/platforms/android/cordova/build: Command failed with exit code 2
And now im kinda lost. I found a forum where they have the same problem: ANDROID_HOME is not set... and one of the guys suggested.
I finally solved it. It was on my users path but not the root users path. I have to run these commands as a root user. I had to edit my root users .bash_profile file.
and one of the others tells how:
In Ubuntu, do all the commands also root
sudo su
gedit ~/.bash_profile
export ANDROID_HOME=/root/Android/Sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
But a third guy said this is a bad idea, so I didnt do it.
I can run the following command:
$ionic serve
And it runs in the browser, but I cant run for android.
I just read your question and it seems you followed the correct way.I faced the same situation during installation process.
The proper set up an Ubuntu machine for Ionic Framework Android development has many steps.Now there are a ton of options to handle this task, but not many bare bones solutions. Most solutions on the internet explain how to use an IDE, or fail to elaborate a complete installation.
After a research,I have found a nice tutorial by Nic Raboy.I followed this tutorial and everything is fine now.
Install Android, Cordova, and Ionic Framework in Ubuntu

Does not recognize android command in path

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.

phonegap build problems (android)

When I try to build my app, using Linux ElementaryOS (Ubuntu 12.04 (I think?)) I get thousands of errors saying:
rm: could not remove file (code EACCESS)
The results of the following show:
$ phonegap -v
3.5.0-0.20.4
$ cordova -v
3.5.0-0.2.4
$ ant -v
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
Any suggestions? I've been battling through several errors for about a week now :(
Thanks in advance!
Update
Update I just changes the permissions of platforms/android too 777 (not a great solution I know). It's now giving me the following:
[Error: An error occurred while listing Android targets] { [Error: /var/www/ppl/app/platforms/android/cordova/build: Command failed with exit code 2] code: 2 } –
Okay, after much pain and anguish... I figured it out.
1). I installed ANT after I installed ionic/cordova/phonegap etc, the best order to install everything in is, java, ant, then cordova/phonegap/ionic.
2). I'm using 64-bit Ubuntu, if you are using the same then you need to install several android 32-bit libs.
3). I deleted the entire project (apart from my css, added js files and my html templates), created a new one using $ ionic start test-app then I ran $ ionic platform add android then ran $ ionic run android and it worked.
4). Make sure your paths are correct in ~/.bashrc mine look as followed:
export PATH=$PATH:/home/ewan/adt-bundle/tools
export PATH=$PATH:/home/ewan/adt-bundle/platform-tools
Here's a video that helped me, especially with the 32-bit libs. https://www.youtube.com/watch?v=zEQIwKK7YjY
Don't give up, it's worth it in the end. Best of luck!

How to fix 'cordova' is not recognized in the Windows command prompt

ERROR
C:\>cordova
'cordova' is not recognized as an internal or external command,
operable program or batch file.
My Environment Path
C:\>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\cmd
;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Windows Kits\8.
1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\B
inn\;C:\Program Files\Microsoft\Web Platform Installer\;**C:\Program Files\ANT\apa
che-ant-1.9.3\bin;C:\Program Files\Java\jdk1.7.0_51\bin;C:\Development\sdk\tools
;C:\Development\sdk\platform-tools;C:\Development\cordova-3.3.0\cordova-android\
bin;**
NB: I have read every available tutorial, followed at least 10 of them, read all the similar questions about 'phonegap' not recognized,, .etc. I have my 'Enabled' registry set to 1 as some solutions have suggested, re-installed 'phonegap' & 'cordova' through NPM install -g phonegap, and same for 'cordova', and I still can't get them to run.
I copied an old phonegap application that I made on another PC, and I can run it through just fine. Hope this would clear anything up.
You do not need to add any cordova folder to the path.
cordova command is a nodejs npm script, what you need is to have the npm folder in your path :
%appdata%\npm\
or if it does not work, use instead
c:\users\YourUserName\AppData\Roaming\npm\
(replace YourUserName with the name of your user profile)
What's strange is that I don't remember I had to change it manually, I think it should be added automatically when installing node and npm.
npm install -g cordova
-g is a global install option and it will make the cordova globally available in AppData\Roaming\npm. Restart the prompt if necessary.
The Method below is the solution of every such problem related to npm, Be it Phonegap, Cordova, Ionic or else...
The concept is that every software installed using npm is saved on this path:
C:\Users\[Your User Name]\AppData\Roaming\npm
So, what we are going to do is just adding the above path to Windows Environment Variable. If you are a begineer, the steps for adding path are as follows:
Go to Control Panel.
Under All Control Panel Items, Go to System.
Click on the Advanced system settings options in the Sidebar.
The System Properties Dialog Box will appear.
You would have done the so far work through searching "Edit Environment Variables" in Search Bar :).
Now, In the System Properties dialog box, there will be Advanced Tab.
In Advanced tab, there will be an option Environment Variables...
Click on it, this will open another Dialog box for Environment Variables.
In System variables, Select Path as shown in image link, and click Edit...
Path attribute in System Variables
Copy the above path, and add it here as shown in link
Copy the Path
Here, you should make sure that the 2 different paths are always seperated by a semicolon ;. Keeping this in mind, add your path to the existing paths.
This will make the application run globally.
This is the General Algorithm of steps employed for any type of Path Configuration.
If You have any issues left, please feel free to ask.
Try running Command Prompt as an administrator..It worked for me
Try restarting the command prompt window. It worked for me.
Place java path before ant path. change the path according to your paths.
C:\Program Files\Java\jdk1.6.0_20\bin;D:\apache-ant-1.9.3\bin;D:\adt-bundle-windows-x86\sdk\tools;D:\adt-bundle-windows-x86\sdk\platform-tools;C:\Program Files\nodejs\;C:\Program Files\Git\cmd
Issue is probably with location of node/npm.
npm working? say npm clear cache
Then even if its not working go to Environment Variables. Ensure nodejs is directed to its directory(wherever you installed it)and npm(which is in Users/YourUsername/AppData/roaming) .. its a hidden folder.
The run npm install npm -g OR (if and only if) that gives issues npm install npm#latest
I recommend getting bower too , so say npm install -g bower
Finally npm install -g cordova
There you go!
Open a Command prompt in Run as administrator mode and
run the below install command
npm install -g cordova
Now check if the command is now recognized. (if needed restart the command prompt)
Now in the visual studio code
goto the terminal
Navigate to the cordova folder
Run the usual commands
cordova platform add android
cordova run android
I had an issue with the default directories that are used by npm. You can get this list by typing 'npm config list' in the command prompt. In my case, for some reason, the cordova installation was going inside a '=' directory. My Command Prompt pointed me to a 'npm.mrc' file inside 'C:\Users\USERNAME' folder when I typed 'npm config list' from where it is picking up the '=' folder inside 'C:\Users\USERNAME\=' as the default folder for cordova. When I uninstalled node, deleted both the 'npm.mrc' file and the '=' folder and reinstalled node and cordova, this issue disappeared. Hope this helps.
I have visual studio installed on my system. Cordova got installed under the following location:
C:\ProgramData\Microsoft\VisualStudio\MDA\c33fb238\taco-toolset-6.3.1
I had to manually add this to PATH.
To know the path where cordova is installed run npm install -g cordova again and the path will be printed on the screen.
After installing Cordova is you face the issue then
check go to Environment variable (My Computer OR My PC > Right Click > Properties > Advance System Settings > Environemnts Variable button)
add
%appdata%\npm\ or c:\users\YourUserName\AppData\Roaming\npm\
(replace YourUserName with the name of your user profile) to System Variable's PATH
Befor trying any of the answers, just open the node.js command prompt and try again.
Press Windows Button => type Node.js => type Cordova inside the node.js command prompt as usual, and thats it. (hopefully)
I ran npx cordova build --release android and it worked. Should just work, but here we are.

Cordova android build fails immediately [Error: spawn EACCES]

I am just getting started with with Cordova ( PhoneGap ) and trying to build my first project with it, however I am running into a problem with my compilation step- when I try to build ( in tracking down the problem I broke down the build step into prepare and compile and the former works fine as far as I know ) I see this:
~/Projects/MyProject$ cordova compile android
Compiling app on platform "android" via command "/media/glenatron/local disk/Projects/Cordova/MyProject/platforms/android/cordova/build"
{ [Error: spawn EACCES] code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }
Now from what I can tell this is a permissions problem, but having no Node or Cordova experience yet I am at a loss as to how to troubleshoot it. It looks as though it is trying to spawn another process - maybe the Android SDK? - and it is failing.
Is there a way I can ask Node or Cordova to give me more information on what is going on or is there a log file somewhere that will help me to track down what the problem is?
Edit: I realised cordova has a --verbose switch and when I activated it I get the above output with an additional couple of lines...
Error: spawn EACCES
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Unfortunately, they don't seem to actually give much more information, like which process it can't start.
For me, this has fixed it:
chmod 777 /Applications/Android\ Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle
It's a permission issue, just execute:
chmod 777 "/media/glenatron/localdisk/Projects/Cordova/MyProject/platforms/android/cordova/build"
That should fix the problem.
Using verbose like Solidak suggested works.
cordova build --release --verbose android
The last command was to access /platforms/android/gradlew so i chmod +x that file and it worked.
Its different for every one, I guess. Running --verbose would give you the file that Cordova needs access to. From there you can chmod 777 <file>. The command you should run to figure out the inaccessible file looks like this: cordova build --release --verbose android
I was facing the same issue. In my case, I had put the sample cordova project on a different ext3 partition than home folder. Since the partition was not NTFS, permissions shouldn't have been a problem. But when I tried all suggested methods (changing permissions, making everything executable), none of them worked. This problem went away as soon as I created the sample cordova folder in my home partition.
For MAC users change the name from "Android Studio" to AndroidStudio. My cordova build was taking back slash() in name of android studio so i changed the name of app.
It is working for me.

Categories

Resources