I'm trying to build a default example app on Linux/Ubuntu 14.04 for Android.
I get a standard error message when doing sudo ionic build android:
Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
(see full log down below)
But if I do
echo $ANDROID_HOME && echo $JAVA_HOME && echo $ANT_HOME
/home/user3123726/Android/Sdk
/usr/lib/jvm/java-8-oracle
/usr/bin/ant
And command android and cordova are also available.
- Android SDK is installed with all platform targets currently available (plus Android SDK Tools,Platform-Tools and Build tools)
- npm 3.3.9 and Node 4.2.2 is installed
- Cordova 5.3.3 was installed via npm
- Ionic 1.7.7 was installed via npm
- Apache Ant 1.9.3
ANDROID_HOME also defined on .bashrc:
export ANDROID_HOME=/home/user3123726/Android/Sdk
export PATH=${PATH}:/home/user3123726/Android/Sdk/platform-tools:/home/user3123726/Android/Sdk/tools
I have no idea what is the reason that the build process fails. Any help is appreciated - thanks!
Here full log of ionic project creation (basically create,add platform and build):
ionic start myApp tabs
Downloading: https://github.com/driftyco/ionic-app-base/archive/master.zip
[=============================] 100% 0.0s
Downloading: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip
[=============================] 100% 0.0s
Updated the hooks directory to have execute permissions Update Config.xml Initializing cordova project
Your Ionic project is ready to go! Some quick tips: [... shortened]
cd myApp
sudo ionic platform add android
Updated the hooks directory to have execute permissions
Downloading Default Ionic Resources
Downloading: https://github.com/driftyco/ionic-default-resources/archive/master.zip
[=============================] 100% 0.0s
Done adding default Ionic resources
Adding icons for platform: android
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.ionicframework.myapp809922
Name: myApp
Activity: MainActivity
Android target: android-22
Copying template files...
Android project created with cordova-android@4.1.1
Running command: /home/user3123726/testing/myApp/hooks/after_prepare/010_add_platform_class.js /home/user3123726/testing/myApp
add to body class: platform-android
Saving platform to package.json file
sudo ionic build android
Running command: /home/user3123726/testing/myApp/hooks/after_prepare/010_add_platform_class.js /home/user3123726/testing/myApp
add to body class: platform-android
Running command: /home/user3123726/testing/myApp/platforms/android/cordova/build
[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/user3123726/testing/myApp/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/user3123726/testing/myApp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
Fixed it:
Was a permission problem
to give cordova the rights
and did
ionic add platform android
ionic build android
without sudo ;)