Ionic android build Error - Failed to find 'ANDROID_HOME' environment variable

前端 未结 12 1476
庸人自扰
庸人自扰 2020-12-23 19:41

I am trying to build android for ionic in linux but its showing me an error like this

     [Error: Failed to find \'ANDROID_HOME\' environment variable. 
           


        
相关标签:
12条回答
  • 2020-12-23 20:02

    Windows - set environment variable permanently:

    setx ANDROID_HOME "C:\Program Files\Android\android-sdk"

    or

    setx ANDROID_HOME "C:\Program Files (x86)\Android\android-sdk"

    0 讨论(0)
  • 2020-12-23 20:02

    For OSX

    Great tutorial here: https://www.youtube.com/watch?v=kY22NSBwV_s

    No need to do any bash commands/symlinks:

    1. Install Java 6 runtime: https://support.apple.com/kb/DL1572?locale=de_DE
    2. Install Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
    0 讨论(0)
  • 2020-12-23 20:02

    In my Case: I have put the correct path for Android and java but still getting the error.

    The problem was that I have added the Android platform using sudo command.sudo ionic cordova platform android.

    To solve my problem: First I have removed the platform android by running command

    sudo ionic cordova platform rm android

    then add the android platform again with out sudoionic cordova platform add android but i get the error of permissions.

    To resolve the error run command

    sudo chmod -R 777 {Path-of-your-project}

    in my case sudo chmod -R 777 ~/codebase/IonicProject Then run command

    ionic cordova platform add android

    or

    ionic cordova run android

    0 讨论(0)
  • 2020-12-23 20:03

    Setup for Linux/Ubuntu/Mint

    1. download Android Studio or SDK only
    2. install
    3. set PATH

    3.1) Open terminal and edit ~/.bashrc

    sudo su
    vim ~/.bashrc
    

    3.2) Export ANDROID_HOME and add folders with binaries to your PATH

    Common default install folders:

    • /root/Android/Sdk
    • ~/Android/Sdk

    Example .bashrc

    export ANDROID_HOME=/root/Android/Sdk
    PATH=$PATH:$ANDROID_HOME/tools
    PATH=$PATH:$ANDROID_HOME/platform-tools
    

    3.3) Refresh your PATH

    source ~/.bashrc
    

    4) Install correct SDK

    When ionic build android still fails it could be because of wrong sdk version. To install correct versions and images run android from command line. Since it is now in your PATH you should be able to run it from anywhere.

    0 讨论(0)
  • 2020-12-23 20:05

    Case: using SO Windows, try:

    set ANDROID_HOME=C:\\android-sdk-windows
    set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
    

    more in: http://spring.io/guides/gs/android/

    Case: you don't have platform-tools:

    cordova platforms list
    cordova platforms add <Your_platform, example: Android>
    
    0 讨论(0)
  • 2020-12-23 20:09

    To add ANDROID_HOME value permanently,

    gedit ~/.bashrc
    

    and add the following lines

    export ANDROID_HOME=/root/Android/Sdk
    PATH=$PATH:$ANDROID_HOME/tools
    

    Save the file and you need not update ANDROID_HOME value everytime.

    0 讨论(0)
提交回复
热议问题