Android Error: Failed to find 'ANDROID_HOME

2019-05-28 10:19发布

问题:

I just started Android development with ionic framework on Linux (Ubuntu).

I successfully created my ionic project using the command:

sudo ionic start demo blank

Now to add the android platform to the project, I ran the command:

sudo ionic platform add android

And this is the result it gave me:

function bold() { [native code] } https://github.com/driftyco/ionic-default-resources/archive/master.zip [=============================] 100% 0.0s Adding android project...

Creating Cordova project for the Android platform:

Path: platforms/android

Package: com.ionicframework.demo504884

Name: demo

Activity: MainActivity

Android target: android-24

Subproject Path: CordovaLib

Android project created with cordova-android@6.0.0

ls: no such file or directory: /home/awa/Desktop/mobile/demo/res/mipmap-*

Installing "cordova-plugin-console" for android

Failed to install 'cordova-plugin-console':CordovaError: 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.

at /home/awa/Desktop/mobile/demo/platforms/android/cordova/lib/check_reqs.js:222:19 at _fulfilled (/home/awa/Desktop/mobile/demo/platforms/android/cordova/node_modules/q/q.js:834:54) at self.promiseDispatch.done (/home/awa/Desktop/mobile/demo/platforms/android/cordova/node_modules/q/q.js:863:30) at Promise.promise.promiseDispatch (/home/awa/Desktop/mobile/demo/platforms/android/cordova/node_modules/q/q.js:796:13) at /home/awa/Desktop/mobile/demo/platforms/android/cordova/node_modules/q/q.js:857:14 at runSingle (/home/awa/Desktop/mobile/demo/platforms/android/cordova/node_modules/q/q.js:137:13) at flush (/home/awa/Desktop/mobile/demo/platforms/android/cordova/node_modules/q/q.js:125:13) at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9)

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.

At first I doubted if it had successfully added the android platform so I ran the same command again (sudo platform add android) and it said platform already existed.

Now seeing the last section of the error, I set the ANDROID_HOME environment variable by putting this code at the end of my .bashrc file located my home directory.

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

I saved the file. In order to build my project, I ran the command:

sudo ionic build android

and it gave the error:

add to body class: platform-android

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.

I verified again to make sure I had succeeded in setting the ANDROID_HOME environment variable correctly. So in the Command line I ran the command echo $ANDROID_HOME and it gave as output:

/home/awa/Android/Sdk

...which is the right directory for my SDK.

I have tried other solutions like setting the environment variables in the .profile file but nothing changed.

Now I am suspecting the problem may have something to do with my sdk version though I'm not entirely sure.

What am I doing wrong, or what I'm I missing?