【问题标题】:Cordova 8, Android 7.1.0, can't install any pluginsCordova 8,Android 7.1.0,无法安装任何插件
【发布时间】:2018-06-28 15:19:41
【问题描述】:

我尝试安装的每个插件都会引发错误,提示找不到清单。确实,该文件不存在。我正在尝试升级 6.4,因为 6.4 似乎不支持 Android 上的 64 位 CPU,无需手动更改构建清单。

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'

如何解决这些错误?

【问题讨论】:

  • 问题是这些大多是 apache 提供的插件。如果更新科尔多瓦的人不更新它们,那就太麻烦了
  • 您没有阅读我更新的答案或者您不理解它。所有 apache 提供的插件在 cordova-android 7.1.0 上都能正常工作。问题是使用源文件标签复制图像并使科尔多瓦疯狂的第 3 方插件之一。其中之一是cordova-plugin-image-picker,删除它,删除cordova-android并再次添加它,看看会发生什么。
  • @jcesarmobile 是的,图像选择器很糟糕。谢谢
  • @TrevorD - 如果你还在寻找合适的cordova-plugin-image-picker 插件,你可以使用这个github.com/Telerik-Verified-Plugins/ImagePicker。我相信它基本上是一样的,但它有适当调整的标签。

标签: android cordova


【解决方案1】:

得到了答案,了不起的社区制作了一个脚本来修补它。

在你的脚本文件夹中创建一个名为

的脚本

patch-android-studio-check.js

把这个放在里面

/**
 * 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; };
};

然后添加这些钩子

<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>

接下来,删除您的插件和平台文件夹。然后运行cordova platform add android,这将重新创建平台并正确添加插件。

第二部分是不要使用图像选择器插件。

2019 年 3 月更新 - 从 Cordova Android 版本 8 开始,这似乎不再需要,实际上会导致问题。

【讨论】:

  • 我仍然遇到与 cordova-android 7 和 8.1.0 相同的问题。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    在您的 config.xml 文件中

    <platform name="android">
    

    添加这一行

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

    【讨论】:

      猜你喜欢
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多