Android Phonegap 应用程序中的错误:未捕获的模块cordova/plugin_list 已定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20890263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:38:47  来源:igfitidea点击:

Error in Phonegap Application: Uncaught module cordova/plugin_list already defined

androidcordovaphonegap-pluginscordova-3

提问by Gthoma2

I have been trying to resolve many issues from having updated from Phonegap 2 to Phonegap 3.3 but I can't seem to fix this one.

我一直试图解决从 Phonegap 2 更新到 Phonegap 3.3 的许多问题,但我似乎无法解决这个问题。

I have read from some users that uncaught module exceptions can cause imported plugins to stop functioning. I am having some odd bugs with a local notification plugin so I would like to fix this issue and see if it helps.

我从一些用户那里了解到,未捕获的模块异常会导致导入的插件停止运行。我的本地通知插件有一些奇怪的错误,所以我想解决这个问题,看看它是否有帮助。

Here is the error as it appears in logcat within Eclipse:

这是 Eclipse 中 logcat 中出现的错误:

[INFO:CONSOLE(79)] "Uncaught module cordova/plugin_list already defined", source: file:///android_asset/www/cordova.js (79)

I know that this is some odd issue arising from the nature of Phonegap 3 (Plugins have been reworked). And I think that the problem lies in importing a cordova_plugins.js script as the top line of that script reads:

我知道这是由于 Phonegap 3(插件已重新设计)的性质而引起的一些奇怪问题。我认为问题在于导入cordova_plugins.js 脚本,因为该脚本的第一行显示:

cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
    "file": "plugins/org.apache.cordova.file/www/DirectoryEntry.js",
    "id": "org.apache.cordova.file.DirectoryEntry",
    "clobbers": [
        "window.DirectoryEntry"
    ]
}, ...

And this is the only place that I can find the existence of cordova/plugin_list as referenced in the error.

这是我可以找到错误中引用的cordova/plugin_list 存在的唯一地方。

However, I am not sure of the correct way of fixing this issue. I did not use plugman to import my plugins, but instead the CLI commands outlined in the Phonegap 3.3 API

但是,我不确定解决此问题的正确方法。我没有使用插件来导入我的插件,而是使用 Phonegap 3.3 API 中概述的 CLI 命令

回答by grytrn

One cause of this problem is importing the cordova_plugins.jsin your html file.

此问题的一个原因是在您的 html 文件中导入了cordova_plugins.js

Check if it is the case for you and remove it.

检查它是否适合您并将其删除。

回答by elMarquis

The file cordova.jsautomatically loads cordova_plugins.js.

文件cordova.js自动加载cordova_plugins.js

So another obvious way to end up with this error is if you inadvertently put the following code twice on your page.

因此,另一个导致此错误的明显方法是,如果您不经意间将以下代码放在页面上两次。

<script type="text/javascript" src="cordova.js"></script> 

I lost hours on this same error only to realise I had added cordova.js at both the top and the bottom of the page.

我在同样的错误上浪费了几个小时,才意识到我在页面的顶部和底部都添加了cordova.js。

回答by Bhavik Modi

You must have to create and deploy any phonegap project/application using Phonegap Command Line Interface

您必须使用 Phonegap 命令行界面创建和部署任何 phonegap 项目/应用程序

To Create any project write following command on command line:

要创建任何项目,请在命令行上编写以下命令:

$ phonegap create <path> <package_name> <project_name>

i.e.

IE

$ phonegap create hello com.example.hello HelloWorld

To add any platform to your project:

要将任何平台添加到您的项目:

cd <path_to_project>
$ phonegap build <platform>

i.e.

IE

cd hello
$ phonegap build ios
$ phonegap build android

To add any plugin feature to your project:

要将任何插件功能添加到您的项目:

cd <path_to_project>
$ phonegap local plugin add <path_to_plugin>

i.e.

IE

cd hello
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git