Cordova build errors

The simple thing I tried works well in the browser. But I am unable to deploy it on an actual device.
cordova run android --device /prepare/build all fail.

(node:18275) UnhandledPromiseRejectionWarning: Error: Unexpected end
Line: 0
Column: 0
Char: 
    at error (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:347:8)
    at end (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:354:32)
    at SAXParser.write (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:588:30)
    at SAXParser.close (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:136:38)
    at XMLParser.close (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/elementtree/lib/parsers/sax.js:52:15)
    at ElementTree.parse (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/elementtree/lib/elementtree.js:272:23)
    at Object.exports.XML (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/elementtree/lib/elementtree.js:606:13)
    at Object.parseElementtreeSync (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:185:38)
    at ConfigFile_load [as load] (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:76:41)
    at new ConfigFile (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:53:10)
(node:18275) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18275) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

A few verbose logs:

ionic:cli-utils Terminal info: { tty: true, ci: false } +0ms
  ionic:cli-utils CLI global options: { _: [ 'cordova', 'run', 'android' ], help: null, h: null, verbose: true, quiet: null, interactive: true, color: true, confirm: null, json: null, device: true, project: null, '--': [] } +3ms
  ionic:cli-utils:lib:project Project type from config: Ionic Angular 3 (ionic-angular) +0ms
  ionic:cli-utils Project name: undefined +115ms
  ionic:cli Context: { binPath: '/usr/local/lib/node_modules/ionic/bin/ionic', libPath: '/usr/local/lib/node_modules/ionic', execPath: '/home/bismeet/ionic/LoginTest', version: '4.0.6' } +0ms
  ionic:cli-utils:lib:integrations:cordova:config Using config.xml: /home/bismeet/ionic/LoginTest/config.xml +0ms
  ionic:cli-utils:lib:integrations:cordova:config Using config.xml: /home/bismeet/ionic/LoginTest/config.xml +23ms
  ionic:cli-utils:lib:hooks Looking for ionic:build:before npm script. +0ms
  ionic:cli-utils:lib:project:ionic-angular:build Looking for ionic:build npm script. +0ms
> ionic-app-scripts build --target cordova --platform android
[18:22:21]  ionic-app-scripts 3.1.11 
[18:22:21]  build dev started ... 
[18:22:21]  clean started ... 
[18:22:21]  clean finished in 3 ms 
[18:22:21]  copy started ... 
[18:22:21]  deeplinks started ... 
[18:22:21]  deeplinks finished in 19 ms 
[18:22:21]  transpile started ... 
[18:22:24]  transpile finished in 3.06 s 
[18:22:24]  preprocess started ... 
[18:22:24]  preprocess finished in less than 1 ms 
[18:22:24]  webpack started ... 
[18:22:24]  copy finished in 3.23 s 
[18:22:29]  webpack finished in 5.34 s 
[18:22:29]  sass started ... 
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
[18:22:30]  sass finished in 798 ms 
[18:22:30]  postprocess started ... 
[18:22:30]  postprocess finished in 5 ms 
[18:22:30]  lint started ... 
[18:22:30]  build dev finished in 9.34 s 
[18:22:32]  lint finished in 2.03 s 
  ionic:cli-utils:lib:hooks Looking for ionic:build:after npm script. +13s
> cordova run android --device --verbose
No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /home/bismeet/ionic/LoginTest/platforms/android/res/xml/config.xml
(node:18378) UnhandledPromiseRejectionWarning: Error: Unexpected end
Line: 0
Column: 0
Char: 
    at error (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:347:8)
    at end (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:354:32)
    at SAXParser.write (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:588:30)
    at SAXParser.close (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/sax/lib/sax.js:136:38)
    at XMLParser.close (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/elementtree/lib/parsers/sax.js:52:15)
    at ElementTree.parse (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/elementtree/lib/elementtree.js:272:23)
    at Object.exports.XML (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/elementtree/lib/elementtree.js:606:13)
    at Object.parseElementtreeSync (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:185:38)
    at ConfigFile_load [as load] (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:76:41)
    at new ConfigFile (/home/bismeet/ionic/LoginTest/platforms/android/cordova/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:53:10)
(node:18378) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18378) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What does your config.xml file look like?

I solved the problem by hardcoding the Android Sdk path in cordova.gradle as the framework was reading the wrong path despite my $ANDROID_HOME being set.