Search code examples
cordovaubuntuwebstormphonegap-cliphonegap

PhoneGap/Cordova WebStorm Ubuntu - Error


I have WebStorm and Android Studio installed. I have my Android SDK and Java environment variables set. I originally had this error (https://github.com/phonegap/phonegap-cli/issues/685) and I fixed that by extracting the templates folder as mentioned in that post.

When I run the PhoneGap demo project in WebStorm I now get:

BUILD SUCCESSFUL

Total time: 0.653 secs

Built the following apk(s): 
    /home/user/WebstormProjects/PageLoad/platforms/android/build/outputs/apk/android-debug.apk


ANDROID_HOME=/home/user/Android/Sdk

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Error: android: Command failed with exit code 2

So I then run phonegap run android --verbose from the CLI and I got:

Built the following apk(s): 
        /home/user/WebstormProjects/PageLoad/platforms/android/build/outputs/apk/android-debug.apk


No scripts found for hook "before_deploy".


ANDROID_HOME=/home/user/Android/Sdk

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Running command: adb devices

Command finished with error code 0: adb devices


No target specified and no devices found, deploying to emulator


Running command: adb devices


Command finished with error code 0: adb devices


Running command: android list avds


Command finished with error code 2: android list,avds


Error: android: Command failed with exit code 2
    at ChildProcess.whenDone (/home/user/WebstormProjects/PageLoad/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

I also tried deleting my android-24 directory from $ANDROID_HOME/Sdk/platforms and same result. That was actually the first thing I tried because rather than getting any error, running PhoneGap in WebStorm was just hanging.

PhoneGap CLI 6.4.5

node 4.5.0

npm 4.3.0

Android SDK Tools 25.3.1


Solution

  • Android SDK tools 25.3.1 broke cordova-android and some other libraries.

    Cordova Android 6.2.1 has been released after that and it's now compatible with Android SDK tools 25.3.1, but it's not compatible with Phonegap CLI 6.4.5 and cordova-android 6.2.1. You have to update to latest Phonegap CLI 6.5.0 first.

    Then you can update your current incompatible android platform with cordova platform update [email protected]

    Or you can remove the existing platform and add the new one (will delete any manual change you did inside yourProject/platforms/android/ folder)

    cordova platform rm android

    cordova platform add [email protected]

    You have to specify the 6.2.1 version because current CLI installs cordova-android 6.1.x by default.

    Also, don't update Android SDK tools to 26.x.x yet because it breaks cordova-android 6.2.1