Resolving Android versionCode float type publishing error with PhoneGap

December 7, 2014, 10:02 pm
Author: James Griffiths

There you are ready to build your Android project - Cordova PhoneGap, Ionic Framework, Ant and the Android SDK are all successfully installed and configured correctly - you've opened up your command line and typed out the following instruction:

ionic build android

You press Enter and wait for the command to run only to be greeted with a failed build message akin to the following...

debug:

-code-gen:
[mergemanifest] Found modified input file
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Found new input file
     [aapt] Generating resource IDs...
     [aapt] /Users/username/path-to-project/platforms/android/ant-build/AndroidManifest.xml:2: error: Error: Float types not allowed (at 'versionCode' with value 'NaN').

BUILD FAILED
/Users/username/path-to-android-sdk/sdk/tools/ant/build.xml:653: The following error occurred while executing this line:
/Users/username/path-to-android-sdk/sdk/tools/ant/build.xml:698: null returned: 1

Total time: 4 seconds

/Users/username/path-to-project/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error code 1 for command: ant with args: debug,-f,/Users/username/path-to-project/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/username/path-to-project/platforms/android/cordova/build: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

Definitely NOT good.

Thankfully resolving the error is quite simple and quick to accomplish.

Open up the config.xml file situated in the root of your Ionic/PhoneGap project and change the following line from:

<widget 
   id="domainSuffix.domainName.ProjectID" 
   version="1.0" 
   xmlns="http://www.w3.org/ns/widgets" 
   xmlns:cdv="http://cordova.apache.org/ns/1.0">

To this instead:

<widget 
   id="domainSuffix.domainName.ProjectID" 
   version="1.0.0" 
   xmlns="http://www.w3.org/ns/widgets" 
   xmlns:cdv="http://cordova.apache.org/ns/1.0">

Notice that the version attribute has an additional decimal place and zero tacked on to the end of the existing value?

Now re-run the following command:

ionic build android

And, presuming you have all the necessary dependencies installed and configured correctly, your Android project should now successfully build.

Categories

« Return to Posts

Post a comment

All comments are welcome and the rules are simple - be nice and do NOT engage in trolling, spamming, abusiveness or illegal behaviour. If you fail to observe these rules you will be permanently banned from being able to comment.