简体   繁体   中英

Cordova 8, Android 7.1.0, can't install any plugins

Every plugin I try to install throws an error saying it can't find the manifest. And it's true, the file isn't there. I am trying to upgrade off 6.4 as 6.4 doesn't seem to support 64bit CPUs on Android without making manual changes to the build manifest.

Failed to install 'cordova-plugin-geolocation': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-file': Error: ENOENT: no such file or directory, open 'C:\\..\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-google-analytics': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-inappbrowser': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-whitelist': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-network-information': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-sqlite-storage': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-android-permissions': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-statusbar': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-device': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

Failed to install 'cordova-plugin-image-picker': Error: ENOENT: no such file or directory, open 'C:\\...\\platforms\\android\\AndroidManifest.xml'

How do I solve these errors?

Got the answer, the amazing community made a script to patch it.

Create a script in your scripts folder called

patch-android-studio-check.js

Put this inside it

/**
 * This hook overrides a function check at runtime. Currently, cordova-android 7+ incorrectly detects that we are using
 * an eclipse style project. This causes a lot of plugins to fail at install time due to paths actually being setup
 * for an Android Studio project. Some plugins choose to install things into 'platforms/android/libs' which makes
 * this original function assume it is an ecplise project.
 */
module.exports = function(context) {
  if (context.opts.cordova.platforms.indexOf('android') < 0) {
    return;
  }

  const path = context.requireCordovaModule('path');
  const androidStudioPath = path.join(context.opts.projectRoot, 'platforms/android/cordova/lib/AndroidStudio');
  const androidStudio = context.requireCordovaModule(androidStudioPath);
  androidStudio.isAndroidStudioProject = function() {  return true; };
};

Then add these hooks

<platform name="android">
   <hook src="scripts/patch-android-studio-check.js" type="before_plugin_install" />
   <hook src="scripts/patch-android-studio-check.js" type="before_plugin_install" />
   <hook src="scripts/patch-android-studio-check.js" type="before_plugin_add" />
   <hook src="scripts/patch-android-studio-check.js" type="before_build" />
   <hook src="scripts/patch-android-studio-check.js" type="before_run" />
   <hook src="scripts/patch-android-studio-check.js" type="before_plugin_rm" />
</platform>

Next, delete your plugins and platforms folder. Then run cordova platform add android and this will recreate the platform and add the plugins correctly.

Second part is don't use the image picker plugin.

Update March 2019 - As of Cordova Android verison 8, this appears to be no longer required and will actually cause problems.

根据docs( cordova android 7)AndroidManifest.xml文件路径已更改。因此,您必须将所有插件更新为支持android 7的版本!

On your config.xml file just under

<platform name="android">

Add this line

<resource-file src="platforms/android/app/src/main/AndroidManifest.xml" target="AndroidManifest.xml" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM