cordova build android error : The system cannot find the path specified. Error: cmd: Command failed with exit code 1

Viewed 3966

I am very new to Ionic2 app development and am trying to build an Android app with it. I want to run the app in Visual Studio emulator and am getting the below error while running 'cordova build android' command. Please help with it! Thanks in advance!

**C:\Devlopment ionic\sample\sampleapp>cordova build android
ANDROID_HOME=C:\Users\d.dutta.chowdhury\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131
The system cannot find the path specified.
Error: cmd: Command failed with exit code 1**

enter image description here

3 Answers

Running this script worked for me

https://github.com/erobertson42/cordova-plugin-xapkreader/blob/cordova-9/scripts/before_install.js

Here's the code. You'll have to run npm i fs-extra q

let fse = require('fs-extra');
let q = require('q');

module.exports = function(context) {
    const deferral = q.defer();
    let target = 'platforms/android/cordova/lib/plugin-build.gradle';

    console.log('scripts/before_install: fixing gradle');

    fse.readFile(target, 'utf8').then((data) => {
        // replace deprecated "compile" configurations with "implementation"
        data = data.replace(/debugCompile (project\(.*)\,.*(\))\n\s*releaseCompile.*/g, 'implementation $1)');

        // replace old Java 1_6 variables with 1_8
        data = data.replace(/(JavaVersion\.VERSION_1)_6/g, '$1_8');

        // fix "cdvCompileSdkVersion" and "cdvBuildToolsVersion" undefined variables
        data = data.replace(/\/\/ GENERATED FILE! DO NOT EDIT!/, match => `${match}
ext {
    apply from: '../../CordovaLib/cordova.gradle'
    cdvCompileSdkVersion = privateHelpers.getProjectTarget()
    cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}
`);

        return fse.writeFile(target, data, 'utf8').then(() => {
            console.log('scripts/before_install: done!');
            deferral.resolve();
        });
    }).catch((e) => {
        deferral.reject('scripts/before_install: error ' + e);
    });

    return deferral.promise;
};
Related