Ubuntu only finds ANDROID_HOME when not running with sudo. When sudo is used, it does not find the installation. Please help!
administrator#administrator-System:~/ap_ids/app$ cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28
Gradle: installed /home/administrator/gradle-6.4.1/bin/gradle
administrator#administrator-System:~/ap_ids/app$ sudo cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: not installed
Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
Android target: not installed
android: Command failed with exit code ENOENT
Gradle: not installed
Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.
Might need to install Android SDK or set up 'ANDROID_HOME' env variable.
Some of requirements check failed
Global paths should be set at /etc/profile. So put your export ANDROID_PATH ... statement there.
But why would you want to run cordova in sudo?
Quoting:
Many Linux distributions support the Linux Standard Base /etc/profile.d directory where configurations such as additional paths directives can go without touching the stock system files.
cat >> /etc/profile.d/some_name.sh << \EOF
PATH=$PATH:/path_to_android/bin
EOF
Related
C:\Users\GINOM HANGSHING\hello>cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
cmd: Command failed with exit code 1 Error output:
'android' is not recognized as an internal or external command,
operable program or batch file.
Gradle: installed C:\Program Files\Android\Android Studio\gradle\gradle-3.2\bin\gradle
Error: Some of requirements check failedenter image description here
Try to update your android platform by
C:\Users\GINOM HANGSHING\hello>cordova platform update android --save
Add System variable, Path. Add "\tools" directory (in addition of "\platform-tools") of your Android SDK folder. There "android.bat" is located.
Restart any open terminals.
How to check Android SDK folder: Android SDK location
If you do not find a \tools folder in your Android SDK folder, you can either try reinstalling your Android SDK or downloading and extracting the tools without the IDE from the links below (Be sure to have read and agreed with the terms of service before downloading any of the command line tools)
Windows no installer: https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip
MacOSX: https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip
Linux: https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
This is how I solved the issue on my machine.
(Deepin 20 community)
After updating my android platform by running the following commands:
cordova platform rm android
and
cordova platform add android
I configured my environment variables and path as follows:
export ANDROID_SDK_ROOT="path-to-android-studio/Sdk"
export JAVA_HOME="/usr/lib/jvm/jdk1.8.0_301/"
export PATH="$PATH:$ANDROID_SDK_ROOT/platform-tools"
export PATH="$PATH:$ANDROID_SDK_ROOT/tools"
export PATH="$PATH:$ANDROID_SDK_ROOT/tools/bin"
export PATH="$PATH:$ANDROID_SDK_ROOT/emulator"
That solved the problem
I have all set up .
I have installed android sdk api 24 and all the necessary tools. I have also tried reinstalling ionic and cordova but it does not work.
This is the error log:
D:\Coursera\Course 4\myapp1\public>ionic platform add android
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.ionicframework.myapp1409522
Name: myapp1
Activity: MainActivity
Android target: android-24
Subproject Path: CordovaLib
Android project created with cordova-android#6.0.0
Installing "cordova-plugin-console" for android
Failed to install 'cordova-plugin-console':Error: cmd: Command failed with exit
code ENOENT
at ChildProcess.whenDone (C:\Users\Sahib\AppData\Roaming\npm\node_modules\co
rdova\node_modules\cordova-common\src\superspawn.js:169:23)
at emitOne (events.js:96:13)
at ChildProcess.emit (events.js:188:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:213:12)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Error: cmd: Command failed with exit code ENOENT
I think you are not adding environment variable.
Please go through following steps :
Windows users developing for Android: You'll want to make sure you have the following installed and set up.
NOTE: Whenever you make changes to the PATH, or any other environment variable, you'll need to restart or open a new tab in your shell program for the PATH change to take effect.
Java JDK
Install the most recent Java JDK (NOT just the JRE).
Next, create an environment variable for JAVA_HOME pointing to the root folder where the Java JDK was installed. So, if you installed the JDK into C:\Program Files\Java\jdk7, set JAVA_HOME to be this path. After that, add the JDK's bin directory to the PATH variable as well. Following the previous assumption, this should be either %JAVA_HOME%\bin or the full path C:\Program Files\Java\jdk7\bin
Apache Ant
To install Ant, download a zip from here, extract it, move the first folder in the zip to a safe place, and update your PATH to include the bin folder in that folder. For example, if you moved the Ant folder to c:/, you'd want to add this to your PATH: C:\apache-ant-1.9.2\bin.
Android SDK
Installing the Android SDK is also necessary. The Android SDK provides you the API libraries and developer tools necessary to build, test, and debug apps for Android.
Cordova requires the ANDROID_HOME environment variable to be set. This should point to the [ANDROID_SDK_DIR]\android-sdk directory (for example c:\android\android-sdk).
Next, update your PATH to include the tools/ and platform-tools/ folder in that folder. So, using ANDROID_HOME, you would add both %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools.
For more please check here and here.
Hope this will help you !!
My final solution was to add the Environmentvariable:
_JAVA_OPTIONS: -Xmx512m
You may vary the 512m by your needs.
Most probably, you need to add "C:\Windows\System32" to your path variable.
I am trying to run a hybrid app on my android phone using ionic using the following command:
sudo ionic run android
However I keep receiving this 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.
I have already added platform tools & tools to PATH updated ANDROID_HOME to point to my sdk root.
The ANDROID_HOME environment variable shows up when I run env and the PATH has the tools and platform tools too. Additionally I can execute android too. It launches the SDK Manager as expected.
Details:
ANDROID_HOME: /home/user/Android/Sdk
$PATH: /home/user/Android/Sdk/tools:/home/user/Android/Sdk/platform-tools
Please help! This is driving me up the wall!
Credit for this goes to #heemayl on AskUbuntu.
https://askubuntu.com/a/783805/247116
sudo sanitizes the environment and by default only keeps certain
environment variables available with modifying the values of some
(e.g. PATH).
You can pass the variable ANDROID_HOME manually:
sudo ANDROID_HOME="/actual/path" ionic run android
Or preserve the current environment:
sudo -E ionic run android
When I tried to install the Android platform, I get a error that the environment variable ANDROID_HOME cant be found, but if I echo it, it proves it exists.
Let me walk you to it:
1) Lets create a new app
dbugger#mercury:~/projects/meteor$ meteor create test
Created a new Meteor app in 'test'.
To run your new app:
cd test
meteor
If you are new to Meteor, try some of the learning resources here:
https://www.meteor.com/learn
2) So far, so good. Lets now install the android platform
dbugger#mercury:~/projects/meteor$ cd test/
dbugger#mercury:~/projects/meteor/test$ meteor add-platform android --verbose
Writing new config.xml
Creating Cordova project
% Creating a new cordova project.
Adding platform Android to Cordova project
=> Errors executing Cordova commands:
While adding platform Android to Cordova project:
Cordova error: CordovaError: Failed to fetch platform android
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
undefined
at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/cordova/platform.js:270:25
at _rejected (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:797:24)
at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:823:30
at Promise.when (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:1035:31)
at Promise.promise.promiseDispatch (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:741:41)
at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:557:44
at flush (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:448:13)
(If the error message contains suggestions for a fix, note that this may not apply to the Meteor integration. You can try running again with the --verbose option to help diagnose the issue.)
3) Well, that did not work out so well. Let's try with sudo
dbugger#mercury:~/projects/meteor/test$ sudo meteor add-platform android --verbose
Adding platform Android to Cordova project
% Adding android project...
android: added platform
Checking Cordova requirements for platform Android
Your system does not yet seem to fulfill all requirements to build apps for Android.
Please follow the installation instructions here:
https://github.com/meteor/meteor/wiki/Mobile-Development-Install:-Android-on-Linux
Status of the requirements:
✓ Java JDK
✗ Android SDK: 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.
✗ Android target: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
✗ Gradle: Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.
Might need to install Android SDK or set up 'ANDROID_HOME' env variable.
4) Wait, what? Im sure that environment variable is set. Let's check it.
dbugger#mercury:~/projects/meteor/test$ echo $ANDROID_HOME
/home/dbugger/Android/Sdk
5) I knew it! So why did it fail...? Let's check it up again
dbugger#mercury:~/projects/meteor/test$ sudo meteor add-platform android --verbose
While adding platforms:
error: android: platform is already added
What?! Now it turns out that it DID install in the end?? What is going on here? I suspect something is greatly misconfigured in my system, but I am not sure what...
you are using sudo!
you probably shouldn't
even if the ANDROID_HOME variable is defined for your current user does not mean it is also defined for the root user, which is what the environment of the sudo call will be.
I'd really recommend against using sudo for meteor. If you can avoid that, then it should work and your problem is solved. Otherwise make sure to define the ANDROID_HOME variable also for the root user, or just use
sudo env ANDROID_HOME=[whatever you want it to be] meteor
instead.
Problem: Meteor cannot find my Android SDK when I try to meteor add-platform android on Linux Mint.
I've set my PATH variable: (echo $PATH)
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jimmy/Android/Sdk/tools:/home/jimmy/Android/Sdk/platform-tools
I've got my ANDROID_HOME variable: (echo $ANDROID_HOME)
/home/jimmy/Android/Sdk
But still, when I run sudo meteor add-platform android --verbose I get:
Adding platform Android to Cordova project
% Adding android project...
android: added platform
Checking Cordova requirements for platform Android
Your system does not yet seem to fulfill all requirements to build apps for
Android.
Please follow the installation instructions here:
https://github.com/meteor/meteor/wiki/Mobile-Development-Install:-Android-on-Linux
Status of the requirements:
✓ Java JDK
✗ Android SDK: 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.
✗ Android target: Android SDK not found. Make sure that it is installed. If it
is not at the default location, set the ANDROID_HOME environment variable.
✗ Gradle: Could not find gradle wrapper within Android SDK. Could not find
Android SDK directory.
Might need to install Android SDK or set up 'ANDROID_HOME' env variable.
Okay, so I figured it out? (I guess)
So, I had already had my PATH and ANDROID_HOME set and everything, I could do echo $PATH and echo $ANDROID_HOME and it would print fine; but when I would run the different commands, it wouldn't work.
however, when I run sudo -s and then the commands, it works fine.
Cheers
ANDROID_HOME must be set to Android/Sdk folder. In my case (Ubuntu) it is:
export ANDROID_HOME="/home/***<user name>***/Android/Sdk"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Put this lines at the end of ~/.profile:
$ gedit ~/.profile
Then $ source ~/.profile
I had the same issue (and now I am stuck to Android target), but to solve Android SDK,
go to Android studio and ensure you remove everything from Android 6,
then that you have Android 5.1.1 installed (with v22 of the platform),
restart your console (I had to restart the laptop)
and normally it doesnt appear again (btw you dont need to use sudo normally)
It's possible that since you're using SUDO - that the PATH / ANDROID_HOME are not present in the root user's session. So try either:
sudo -s
export PATH=...
export ANDROID_HOME=...
meteor ...
or avoid using sudo.