13
votes

I am getting error while building phonegap android app on my linux (ubuntu 12.04) machine. I have installed nodejs, set JAVA_HOME, ANT_HOME, ANDROID_HOME vars and $JAVA_HOME/bin, $ANT_HOME/bin, $ANDROID_HOME/tools, $ANDROID_HOME/platform-tools to the path. when I am running command phonegap local build android, I am getting following error:

ME@My-PC:/dos/PhoneGap/HelloWorld$ phonegap local run android 
[phonegap] compiling Android...
    [error] An error occurred while building the android project. 
module.js:340
    throw err;
          ^
Error: Cannot find module 'shelljs'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/dos/PhoneGap/HelloWorld/platforms/android/cordova/lib/build.js:22:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Thanks for Helping

6
Did you run npm install phonegap to install all of the dependencies, like shelljs? - MBillau
@MBillau yes i have installed phonegap by this command - djhs16
Have you tried "$ phonegap build android "? As you tried "$ phonegap local build android"? - Amit Gupta
@Amit Gupta, I want it to build locally. - djhs16
What is your path? Is it really ME@My-PC:/dos/...? Maybe there are problems with the hyphen in My-PC? I know there have been problems with spaces and hyphens before... - MBillau

6 Answers

36
votes

you must

$cordova platform remove android

$cordova platform add android

because there is directory is missing in

platforms/android/cordova/node_modules/shelljs

or you can create another app and copy the missing file and add it in your app

Recently solution

in terminal go to your app then

cd platforms/android/cordova
sudo npm install shelljs

it's working fine with me

7
votes

I already installed shelljs:

sudo npm install shelljs -g

But I needed to set NODE_PATH

export NODE_PATH=/usr/local/lib/node_modules

Not sure why it was missing...

2
votes

I have needed to update cordova-android engine (from 3.5.1) to 3.6.0 (because required by the splashscreen plugin, here)

To build the Android project (and evict the above errors), i have added in the package.json file (of my Cordova project root folder), the following npm dependencies:

"dependencies": {
    "q": "^1.2.0",
    "shelljs": "^0.4.0",
    "which": "^1.0.9"
  }
0
votes

I was getting the exact same error message on OS X 10.9 for my phonegap android app. The problem was that I set my JAVA_HOME variable incorrectly. Once it was correct, I needed to remove and add the android platform in cordova. It is possible that this may be your issue, so this is how I fixed it:

In my .zshrc file added the line export JAVA_HOME=$(/usr/libexec/java_home)

Finally I had to remove the platform and add it again in order for cordova to properly utilize java.

$cordova platform remove android

$cordova platform add android


Note: While troubleshooting, I installed the JDK, which may be necessary.

0
votes

I suggest you to ensure the required libs are installed running:

sudo npm install -g cordova gulp
0
votes

The Problem was with directory and user permissions. I created the project in home directory, and it was working.