什么是cordova_plugins.json文件?Cordova在初始化时请求它

Eri*_*c H 33 phonegap-plugins cordova

我正在尝试调试cordova_plugins.json文件用于什么?

到目前为止我使用多个插件,我从未与此文件进行过交互.我想弄清楚为什么cordova在初始化时对此文件发出xhr请求.

在查看我的控制台时,每次我在Chrome中测试我的应用程序时都会看到这个404错误,并且想要理解为什么需要这个文件.

Fel*_*ets 14

这似乎是Cordova 2.6.0中引入的一个功能,至少我在这个版本中注意到了.在这一点上,我找不到任何文档,我没有很多细节,但是现在我解决了404问题,在我的项目的根目录中添加了一个虚拟的cordova_plugins.json文件.

由于它需要一个有效的json文件,我在文件中添加了以下内容:"只是Cordova 2.6.0所需的虚拟文件"


Eti*_*gné 11

看来这是一个已经讨论过的知识问题:这里

创建一个虚拟的json文件并没有解决我的问题...确实,在cordova-2.7.0.js的末尾删除了整个代码块

// Try to XHR the cordova_plugins.json file asynchronously.
try { // we commented we were going to try, so let us actually try and catch
    var xhr = new context.XMLHttpRequest();
    xhr.onload = function() {
        // If the response is a JSON string which composes an array, call handlePluginsObject.
        // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
        var obj = this.responseText && JSON.parse(this.responseText);
        if (obj && obj instanceof Array && obj.length > 0) {
            handlePluginsObject(obj);
        } else {
            finishPluginLoading();
        }
    };
    xhr.onerror = function() {
        finishPluginLoading();
    };
    xhr.open('GET', 'cordova_plugins.json', true); // Async
    xhr.send();
}
catch(err){
    finishPluginLoading();
}
Run Code Online (Sandbox Code Playgroud)

并通过调用finishPluginLoading()来替换它将解决问题.


Bla*_*ack 9

Adobe的Filip Maj在其他地方已经说过,这是(到目前为止)部分实现的插件工具.在Cordova的未来版本中,插件工具将自己生成cordova_plugins.json.

就目前而言,他已经说完全忽略了404错误.如果您认为它影响了您的应用程序,您应该向Cordova提交错误.

[请注意,如果您自己添加虚拟文件,可能会影响插件的集成]


net*_*lex 6

我确认弗朗西斯的回答,并注意到2.7如果插入一个虚拟文件,有时它会在错误"processMessage failed:invalid message:"(line cordova-2.7.0.js:971)上启动一个无限循环.保持404错误似乎确实更安全.(参考:https://groups.google.com/forum/? fromgroups#!topic / phonegap/slbvvtEw0aw)

  • 为了摆脱无限循环,我不得不从index.html文件中删除cordova-2.7.0.js文件的<script>包含.显然,Ripple会动态加载它.我还必须通过Ripple访问该网站:http://localhost/my_app/index.html?enableripple = cordova-2.7.0 (2认同)