Problem in getting version code and version name while build release ionic 2.2

Ionic Info output:

Cordova CLI: 6.5.0
Ionic Framework Version: 3.9.2
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 3.1.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 3.19
Node Version: v6.9.1
Xcode version: Not installed

I installed a fresh ionic app (tabs template) using
ionic start testapp

and then checked ionic serve and everything was working fine. Then i added platform android. The added platform was android@6.1.2

Then i did ionic run android --device and it was working fine. and the version was showing correct. Finally i did a ionic build android --release. The release build is not showing the version correctly. The version is displayed as null.

I have verified the config.xml at the root of my app, the widget tag has the correct versioncode and versionname defined. I have tried directly supplying the versionname and code in the build.gradle.

defaultConfig {
versionCode 5
versionName "1.1"
}