ionic3构建过程中遇到的找不到AndroidManifest.xml的问题
问题如下:
Failed to install 'ionic-plugin-keyboard': Error: ENOENT: no such file or directory, open '/Users/theo/Projects/mobile/platforms/android/AndroidManifest.xml' at Object.fs.openSync (fs.js:651:18) at Object.fs.readFileSync (fs.js:553:33) at Object.parseElementtreeSync (/Users/theo/Projects/mobile/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27) at new AndroidManifest (/Users/theo/Projects/mobile/platforms/android/cordova/lib/AndroidManifest.js:29:20) at AndroidProject.getPackageName (/Users/theo/Projects/mobile/platforms/android/cordova/lib/AndroidProject.js:99:12) at Api.addPlugin (/Users/theo/Projects/mobile/platforms/android/cordova/Api.js:223:57) at handleInstall (/Users/theo/.nvm/versions/node/v8.1.2/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:594:10) at /Users/theo/.nvm/versions/node/v8.1.2/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:357:28 at _fulfilled (/Users/theo/.nvm/versions/node/v8.1.2/lib/node_modules/cordova/node_modules/q/q.js:787:54) at self.promiseDispatch.done (/Users/theo/.nvm/versions/node/v8.1.2/lib/node_modules/cordova/node_modules/q/q.js:816:30)
这个问题的原因就是新版本的cordova 7.0.0及以上版本对于新的AndroidManifest.xml路径还没有更新,导致找不到AndroidManifest.xml,解决方法如下:
npm uninstall -g cordova
npm install -g cordova@6.5.0
即卸载新版本,安装7.0.0以下的版本,这时候再构建,问题解决。
上面的如果还解决不了的话可以再运行如下命令:
cordova platform rm android
cordova platform add android
通过删除Android的支持再添加回来,问题解决。
原文链接:https://github.com/ionic-team/ionic-plugin-keyboard/issues/304
还有另一种解决办法,这是Cordova官方的解决办法:
在config.xml将路径改为正确路径
<!-- An existing config.xml --> <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge"> <!-- needs to change to --> <edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application" mode="merge">
链接:https://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html