mobiemp
mobiemp

Reputation: 43

cordova build android fails: Cannot find module 'C:[...]\platforms\android\cordova\lib\AndroidStudio'

I am building an Ionic app and I'd like to use the plugin firebasex.

Unfortunately, when running Ionic cordova build/run android, I am getting the following error:

Cannot find module 'C:\[...]\platforms\android\cordova\lib\AndroidStudio'

I have tried everything: remove and add back the platform, cleaning caches, re installing modules via npm install ...

Here's my environnement:

Ionic:

Ionic CLI : 5.2.3

Utility:

cordova-res : not installed
native-run : 0.2.8

System:

NodeJS : v10.15.3

npm : 6.4.1

OS : Windows 10

I just want the app to build and deploy.

Upvotes: 0

Views: 2173

Answers (3)

mobiemp
mobiemp

Reputation: 43

Found the solution:

Create file \platforms\android\cordova\lib\AndroidStudio.js

/*
 *  This is a simple routine that checks if project is an Android Studio Project
 *
 *  @param {String} root Root folder of the project
 */

/* jshint esnext: false */

var path = require('path');
var fs = require('fs');
var CordovaError = require('cordova-common').CordovaError;

module.exports.isAndroidStudioProject = function isAndroidStudioProject (root) {
    var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res'];
    var androidStudioFiles = ['app', 'app/src/main'];

    // assume it is an AS project and not an Eclipse project
    var isEclipse = false;
    var isAS = true;

    if (!fs.existsSync(root)) {
        throw new CordovaError('AndroidStudio.js:inAndroidStudioProject root does not exist: ' + root);
    }

    // if any of the following exists, then we are not an ASProj
    eclipseFiles.forEach(function (file) {
        if (fs.existsSync(path.join(root, file))) {
            isEclipse = true;
        }
    });

    // if it is NOT an eclipse project, check that all required files exist
    if (!isEclipse) {
        androidStudioFiles.forEach(function (file) {
            if (!fs.existsSync(path.join(root, file))) {
                console.log('missing file :: ' + file);
                isAS = false;
            }
        });
    }
    return (!isEclipse && isAS);
};

Upvotes: 2

Velusamy Venkatraman
Velusamy Venkatraman

Reputation: 736

Can you try the flowing,

  1. This is helps to add platform in your app.
  2. Check ANDROID_HOME setted correctly. echo $ANDROID_HOME
  3. If you setted correctly. but it was not showing in command prompt means use source ~/.bash_profile or source ~/.bashrc

I hope these are helps you

Upvotes: 0

Fearcoder
Fearcoder

Reputation: 788

Can you do the following steps:

  1. cordova clean android (or IOS)

  2. rm -rf node_modules

  3. npm install

  4. cordova build android

Check out this source on github:

https://github.com/ionic-team/ionic-cli/issues/3301

Hope this helps for you

Upvotes: 0

Related Questions