`create` script for Cordova Android fails to create new project – errors with java/ant configuration

I’m trying to create a new Android project using Cordova/Phonegap.

I have downloaded cordova-2.9.0, and the ADT Bundle for Mac.

I extracted ADT to ~/Developer/Android, and added it to my PATH:

export PATH="$HOME/Development/Android/sdk/tools:$PATH"
export PATH="$HOME/Development/Android/sdk/platform-tools:$PATH"

I then try to run the cordova create script, but it fails:

โ†’  bin  sudo ./create ~/Projects/myproject/cordova-android com.mydomain.myproject myproject
Password:

BUILD FAILED
/Users/asgeo1/Development/Android/sdk/tools/ant/build.xml:714: The following error occurred while executing this line:
/Users/asgeo1/Development/Android/sdk/tools/ant/build.xml:728: Compile failed; see the compiler error output for details.

Total time: 1 second
An unexpected error occurred: ant jar > /dev/null exited with 1
Deleting project...

Not very helpful. So I edit the Cordova create script so it will output some more information.

    # COMMENTED OUT piping to /dev/null:
    #
    # compile cordova.js and cordova.jar
    pushd "$BUILD_PATH"/framework # > /dev/null
    ant jar #> /dev/null
    popd  #> /dev/null

Then I re-ran the create script:

โ†’  bin  sudo ./create ~/Projects/myproject/cordova-android com.mydomain.myproject myproject
~/Downloads/cordova-2.9.0/cordova-android/framework ~/Downloads/cordova-2.9.0/cordova-android/bin
Buildfile: /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/build.xml

-pre-build:

-check-env:
 [checkenv] Android SDK Tools Revision 22.0.5
 [checkenv] Installed at /Users/asgeo1/Development/Android/sdk

-setup:
     [echo] Project Name: Cordova
  [gettype] Project Type: Android Library

-build-setup:
[getbuildtools] Using latest Build Tools: 18.0.1
     [echo] Resolving Build Target for Cordova...
[gettarget] Project Target:   Android 4.3
[gettarget] API level:        18
     [echo] ----------
     [echo] Creating output directories if needed...
     [echo] ----------
     [echo] Resolving Dependencies for Cordova...
[dependency] Library dependencies:
[dependency] No Libraries
     [echo] ----------
     [echo] Building Libraries with '${build.target}'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] No changes in the AndroidManifest files.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] No changed resources. R.java and Manifest.java untouched.
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 104 source files to /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/bin/classes
    [javac] /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/src/com/squareup/okhttp/Connection.java:171: method does not override a method from its superclass
    [javac]   @Override public void close() throws IOException {
    [javac]    ^

And there’s another 40 errors like the one above, regarding @override.

From what I can tell on Google, this is because in jdk 1.6 and above, the @override annotations changed. (or something like that): Why is javac failing on @Override annotation

OK, so I work out that the Android SDK configuration for ant is in a file called build.xml. Low and behold, it has some settings for Java 1.5:

<property name="java.target" value="1.5" />
<property name="java.source" value="1.5" />

If I change those values to 1.6 or 1.7, I get a java error when re-running the Cordova create script:

-compile:
    [javac] Compiling 104 source files to /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/bin/classes
    [javac] javac: invalid source release: 1.7
    [javac] Usage: javac <options> <source files>

I’m really scratching my head here. I’m not an expert on Java, so I don’t get what is going on here.

Does anyone know how to run the create script for Cordova Android on OSX ?

UPDATE

After following @cartland’s advice below I was able to get rid of the @Override errors. Still getting one last error though:

-compile:
[javac] Compiling 104 source files to /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/bin/classes
[javac] /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/src/org/apache/cordova/InAppBrowser.java:523: error: cannot find symbol
[javac]                 settings.setPluginsEnabled(true);
[javac]                         ^
[javac]   symbol:   method setPluginsEnabled(boolean)
[javac]   location: variable settings of type WebSettings
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 error

I’ll try and work out what that is – but if anyone knows, please post an answer ๐Ÿ™‚

UPDATE 2

I know what the 2nd error is. It’s mentioned here: https://developer.motorolasolutions.com/thread/3640

Cordova 2.9.0 is not compatible with Android SDK 18. I need to use Cordova 3.0.0 with Android SDK 18. (or conversely downgrade the Android SDK to 17)

Answer

I’m running Ubuntu 10.4 64bit; Oracle JDK 1.7.0_25-b15; Eclipse Kepler; Android SDK 4.3; PhoneGap 3.0.

Had exactly the same problem as you using the CLI. Loading the project into Eclipse worked fine (~/.cordova/lib/android/cordova/3.0.0/framework/.project). As Eclipse uses it’s own internal Java compiler, I figured there was a problem with the Oracle install I was using, and there was – sort of.

It turned out that some application had installed a version of tools.jar (amongst others) from an earlier JRE into the Java ext folder. Seems strange to me that javac would load dependant jars from here prior to jars in it’s own lib folder but that seems to be the precedence order. Anyway, I removed all files from the ext folder and everything worked properly.

  • JDK location: /usr/lib/jvm/java-7-oracle/
  • Ext location: /usr/java/packages/lib/ext/

I don’t have my Mac on me to check locations but try /Library/Java/Extensions or ~/Library/Java/Extensions

I didn’t need to make any other changes. However while experimenting, I did try setting the following properties in the project’s ant.properties file. 1.5, 1.6, 1.7 all work.

  • java.target=1.5
  • java.source=1.5

Leave a Reply

Your email address will not be published. Required fields are marked *