Giter Site home page Giter Site logo

Comments (1)

breautek avatar breautek commented on May 26, 2024

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.

from cordova-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.