Error adding android platform on Ubuntu 14.04

Hi,
I heard about IonicFramework and trying to learn and use it for my one of the project. I am using this for the first time.
I installed cordova and started a new ionic project following your tutorial:

sudo ionic start projectName blank

It was successful, however I’m getting the following error when trying to add android platform:

   sudo ionic platform add android
Running platform task...
Adding platform android
Creating android project...

/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occurred while listing Android targets
    at /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/lib/check_reqs.js:87:29
    at _rejected (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:808:24)
    at /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:752:41)
    at /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:574:44
    at flush (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)
Error: /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/create: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131: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)
Unable to add platform android. Please see console for more info.

I googled for the solution and found some useful suggestions but none of them solved.
I have added the path to android sdk, ant etc on ./bashrc file as following:

export HOME="/home/tushar"
export ANDROID_HOME="$HOME/Development/adt-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/Development/adt-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"

export ANT_HOME="$HOME/Development/ant"
export PATH="$PATH:$ANT_HOME/bin"

But I am still getting the problem.
Any Suggestions???

Thanks,
Tushar

Have you read our installation guide?

http://ionicframework.com/docs/guide/installation.html

Are you running a 64-bit of Ubuntu, you’ll need to add the 32-bit version of the android libraries.

sudo apt-get install ia32-libs

Hi,
Yes I’m running 64 bit Ubuntu 14.04.
I have read in Ubuntu forum that there isn’t need of the ia32-libs package anymore (since 12.04 to be exact).

When I run sudo apt-get install ia32-libs , I get the following message:

Package ia32-libs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  lib32z1 lib32ncurses5 lib32bz2-1.0

E: Package 'ia32-libs' has no installation candidate

Alright, let me check with one of the devs who runs ubuntu. This is good to know!

In the mean time, check out this post

There are a number of sources suggesting ia32-libs is needed on 64 bit Ubuntu, but only the below are actually needed.
sudo apt-get install -y libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386
Reference

Also, I installed Ant via the Ubuntu software center, so my path is as follows in the .bashrc:
export ANT_HOME=/usr/share/ant

1 Like

I seem to be having the same issue as the OP. I followed the Ionic installation guide and the “Comprehensive guide…” and as far as I can tell everything is installed correctly. I can run adb from the terminal as well as ant. Is there something else I can check? I can initialize the project but when I try to: sudo ionic platform add android i get that same error.

Would really like to try ionic out on this new project, any help is appreciated.

Hmm, you may want to check out ionic-box

https://github.com/driftyco/ionic-box

It should take care of all the issues of installing and setting up the dev environment

I think it’ll be better to put your PATH in your ~/.profile.

PATH = ${PATH}:<absolute_Path_to_adt_bundle>/sdk/tools
PATH = ${PATH}:<absolute_Path_to_adt_bundle>/sdk/platform-tools

From the terminal just run android (SDK Manager) and install at least android-19 target (Android 4.4.2 API-19). You can iinstall more. This requires Internet connection for the download and installation to continue.

After this installation, verify that ant is installed and that you have a working jdk. Make sure not more than one is active. use sudo update-alternatives ... for that.

Your ionic should work well now.

check if you have an android target installed: android list target.
Your output should look like

id: 2 or "android-19"
     Name: Android 4.4.2
     Type: Platform
     API level: 19
     Revision: 3
     Skins: WQVGA400, QVGA, WSVGA, WQVGA432, HVGA, WXGA800, WVGA854, WVGA800 (default), WXGA720, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a, default/x86
......

Thanks for the replies.

Not sure what fixed it, but after posting (and before your reply) I had moved the sdk into my home path and updated my .profile (was previously pointing to original tools/platform-tools paths). I then installed android-19 target (only had android-20 target installed). I’m sure I did 100 other things, but those are the significant changes I recall and now I can run ionic platform add android and it works!

Now, when I try to run ionic emulate android I get a “PANIC: Cannot open GalaxyS3”. This is the device I setup using the android avd tools. This is probably something I should ask in the android dev forums as I can’t even launch the device from the android device manager.

I hate to dig up a dinosaur here, but for anyone looking at this in the future, I made a script that will accomplish this in Ubuntu:

It will download and install everything required for Ionic Framework development. It works for 64-bit and 32-bit installs and has been tested specifically on 14.04.

I’ve been having same issue, I will try out your method. thanks again for sharing.

ta.

I can confirm that moving the andoid sdk in home directory could be a solution. if ANDROID_HOME is not set, cordova will look in the home/android-sdk folder

maybeSetAndroidHome(path.join(process.env[‘HOME’], ‘android-sdk’));

from APP/platforms/android/cordova/lib/check_reqs.js line 180.

It’s easier to update your ~/.bashrc with this line

export ANDROID_HOME=<path to adt bundle>/sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools

Then close all terminal windows and open them. Or you just run ~/.profile and continue in that same tab.