简体   繁体   中英

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

  1. Install Node.js

     $ sudo apt-get install -y nodejs $ node -v v5.0.0 
  2. 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.

  1. 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 
  2. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM