首页 > 解决方案 > cordova build android 失败:找不到模块'C:[...]\platforms\android\cordova\lib\AndroidStudio'

问题描述

我正在构建一个 Ionic 应用程序,我想使用该插件firebasex

不幸的是,在运行 Ionic cordova build/run android 时,我收到以下错误:

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

npm install我已经尝试了一切:删除并重新添加平台,清理缓存,通过...重新安装模块

这是我的环境:

离子:

离子 CLI:5.2.3

效用:

cordova-res:未安装
本机运行:0.2.8

系统:

节点JS:v10.15.3

npm:6.4.1

操作系统:Windows 10

我只想构建和部署应用程序。

标签: androidcordovaionic-frameworkionic4

解决方案


找到了解决方案:

创建文件 \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);
};

推荐阅读