Ionic platform add android: Error: Your android platform does not have Api.js


#1

Hi All,

My ionic serve works fine but when i try to add android platform then it is showing bellow error:


Adding android project…

Using this version of Cordova with older version of cordova-android is deprecated. Upgrade to cordova-android@5.0.0 or newer.

Error: Your android platform does not have Api.js

Below is the output with --verbose option:

Task: title=platform, name=platform, summary=Add platform target for building an Ionic app, =, [options]=, title=Do not add default Ionic icons and splash screen resources, boolean=true, title=Do not save the platform to the package.json file, boolean=true, isProjectTask=true, run=function run(ionic, argv, rawCliArguments) {
var appDirectory = process.cwd();
var cmdName = process.argv[2].toLowerCase();
var rawArgs = rawCliArguments.slice(0);
var argumentName = argv._[2];

var isAddCmd = argv..indexOf(‘add’) !== -1;
var isRmCmd = argv.
.indexOf(‘rm’) !== -1 || argv._.indexOf(‘remove’) !== -1;
var addResources = isAddCmd && !(argv.noresources || argv.r);

// ensure the content node was set back to its original
return ConfigXml.setConfigXml(appDirectory, {
resetContent: true,
errorWhenNotFound: false
})
.then(function() {
if (addResources) {
return IonicResources.copyIconFilesIntoResources(appDirectory)
.then(function() {
return IonicResources.addIonicIcons(appDirectory, argumentName);
});
}
})
.then(function() {
var optionList = cordovaUtils.filterArgumentsForCordova(cmdName, argv, rawArgs);
return cordovaUtils.execCordovaCommand(optionList);
})
.then(function(runCode) {

// We dont want to do anything if the cordova command failed
if (runCode !== 0 || argv.nosave) {
  return;
}

if (isAddCmd) {
  log.info('Saving platform to package.json file');
  return State.savePlatform(appDirectory, argumentName);
}
if (isRmCmd) {
  log.info('Removing platform from package.json file');
  return State.removePlatform(appDirectory, argumentName);
}

})
.catch(function(ex) {
if (ex instanceof Error) {
log.error(ex);
}
});
}
Looking up Ionic root, cwd: /Users/ankitkau/Ankit Kaushik/ionic/mapskool-latest
Ionic root directory: /Users/ankitkau/Ankit Kaushik/ionic/mapskool-latest
Package.json found scripts: ionic:build=ionic-app-scripts build, ionic:serve=ionic-app-scripts serve

Npm scripts: ionic:build=ionic-app-scripts build, ionic:serve=ionic-app-scripts serve
Gulpfile found: false

ConfigXml.setConfigXml /Users/ankitkau/Ankit Kaushik/ionic/mapskool-latest resetContent=true, errorWhenNotFound=false
Executing cordova cli: platform add android --verbose
No scripts found for hook “before_platform_add”.

saving

Running command: npm install “/Users/ankitkau/Ankit Kaushik/ionic/mapskool-latest/android” --save

Command finished with error code 0: npm install,/Users/ankitkau/Ankit Kaushik/ionic/mapskool-latest/android,–save

Adding android project…

Using this version of Cordova with older version of cordova-android is deprecated. Upgrade to cordova-android@5.0.0 or newer.

Error: Your android platform does not have Api.js


#2

Can someone have a look at this please?


#3

I had this problem. In my case, I solved it forcing cordova upgrade:

npm install -g cordova@6.0.0

Next:

ionic platform rm android
ionic platform add android


#4

Please edit your post and use the </> button above the post input field to format your code or error message or wrap it in ``` (“code fences”) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.


#5

yes thank you but we need a solution for cordova 7


#6

npm install -g cordova@7.0.0


#8

My issue was little more sillier than i thought. I actually added android platform at wrong place because of which android folder was appearing in root directory. Deleted and added the platform again and its working fine now. Thank you.


#9

I have just updated Cordova to latest version and get this error. I also updated node.

Turns out I had some untitled platforms appearing and I deleted them.


#10

I got it working by deleting the platforms folder.


#11

try cordova platform build android


#12

this also works for me thanks


#14

thanks it works after uninstalling and install platform