Closed thangkho closed 2 months ago
I create new project and add android platform. When I run 'sudo cordova build android' it build FAILED
TL;DR; Shouldn't use sudo. If you npm installed
or cordova plugin/platform add
with sudo
, then running without sudo
may be difficult. In which case you may want to delete your node_modules/
, plugins/
, and platforms/
so you can reinstall without sudo
. This makes all the files owned by your own user, not by the root
user.
When you run with sudo
(aka root) you may be running under a different environment. For example it looks like your Android SDK and JDK is installed for a local single user, v002024
, not the root
user.
While echo $ANDROID_HOME
and sudo echo $ANDROID_HOME
will produce a printout as expected. Running:
sudo su
echo $ANDROID_HOME
does not produce what you'd expect. Cordova launches several sub-processes including calling on gradle, java, and other binaries, so it's about the equivalent of doing the above. It won't have the environment variables that you set as expected. The root user account needs to be configured appropriately for this to work, HOWEVER, it's also not secure to be running under the root. You're running a lot of software that I'm sure you haven't vetted yourself, or it can change easily without you knowing. Using root for develpoment tools makes you very susceptible to supply chain attacks so it's advisable to install locally without the sudo
/root privileges.
If you've installed NodeJS through the official NodeJS channel, the NPM shipped is configured to install global packages in a directory where root is required to access. Which might be why you're using sudo
to begin with. If this is the case, have a read at fixing-npm-permissions.md, which allows you to reconfigure to a directory that your local user has read/write access to. This will avoid the sudo
requirement when installing global packages. After changing the install prefix, you will have to reinstall your global packages.
If you want to quickly confirm if this the issue without messing with your environment, try doing this:
cd ~/
cordova create testapp
cd testapp
cordova platform add android
cordova build android
The build should be successful, no sudo
was use.
I create new project and add android platform. When I run 'sudo cordova build android' it build FAILED
I flow https://github.com/apache/cordova-android/issues/1613 and add JAVA_HOME, ANDROID_HOME, ANDROID_SDK_ROOT into zshrc export PATH="/Users/v002024/FlutterDev/flutter/bin:$PATH" export PATH="$PATH":"$HOME/.pub-cache/bin" export JAVA_HOME="/Users/v002024/Library/Java/JavaVirtualMachines/jdk1.8.0_381.jdk/Contents/Home" export ANDROID_HOME=/Users/v002024/Library/Android/sdk export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/platform-tools export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/emulator
When I check ANDROID_HOME and ANDROID_SDK_ROOT it return same value
In Android Studio I have Android SDK Location and build tools
I check in build-tools folder, 30.0.2 already:
When I run cordova requirements, it's ok
I use cordova 12.0.0 (cordova-lib@12.0.1)
Please help me fix it!