Cordova could not load API for android project

13.2k views Asked by At

I've been trying to run android project using Visual Studio 2017 and Cordova. When i try to run the app on the android emulator from command prompt it doesnt work and said that it could not load API for the android project from API.js. Is there any thing I can do to fix the problem?

Attached is the screenshot from the command prompt with the error mentioned.

I have tried to use the command cordova emulate android but to no avail.

5

There are 5 answers

4
Niklas Merz On

I would you advise you to avoid Visual Studio for Cordova development. As far as I know they discontinued the support for Cordova and you might be using a very old version.

You can manage your Cordova project with the official command line interface and edit your code with the editor of your chossing like Visual Studio or Visual Studio Code.

Make sure to use the latest version of the documentation and prepare your environment for the platforms like Android

2
pizzamonster On

First remove all node modules:

rm -rf node_modules/

Then install them again:

npm i

That should solve your issue.

0
Hatem Ahmed On

remove platform android, then add it back again this should solve your problem ,

0
saknarak On

I found solution, root cause is package.json type must be commonjs

remove "type": "module" or change to "type": "commonjs" first and then cordova platform remove android cordova platform add android

0
Sunil Kumar On

This can be fixed easily by removing and adding platform again as mentioned below.

cordova platform rm android

and then add it again

cordova platform add android@latest

Note: Keep a backup of platforms/android as sometime user have manually added changes in platform folder, so that will be lost. @latest was added just to make sure you are using all latest feature, you can avoid that if not needed or want to use a specific version, then use that.