What is the cordova_plugins.json file for? Cordova

2020-02-07 19:30发布

I am trying to debug what the cordova_plugins.json file is used for?

I am using multiple plugins so far and I have never interacted with this file. I want to figure out why cordova makes an xhr request for this file at initialization.

When looking at my console I keep seeing this 404 error every time I test my app in Chrome and like to understand why this file is necessary.

8条回答
霸刀☆藐视天下
2楼-- · 2020-02-07 20:07

That file did represent a bug/loose end in previous versions of Cordova/PhoneGap - and nurieta's suggested fix did resolve the (harmless) error thrown in its absence. The successor to this file is now created and handled by the Cordova/PhoneGap CLI entirely and resides in /myapp/platforms/#platform#/www/cordova_plugins.js

Bottom line - though the file sorta exists still this is no longer an issue as of Cordova 3.0.

查看更多
做自己的国王
3楼-- · 2020-02-07 20:13

It seems this is a know issue as discussed: here

Creating a dummy json file did not solved the problem for me... Indeed, remove this entire chunk of code at the end of 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();
}

and replace it with a call to finishPluginLoading() will solve the problem.

查看更多
Anthone
4楼-- · 2020-02-07 20:19

I actually mock this file as an empty json file whose content is : "{}" and -using cordova 2.6- that seems to fix issues. There was not an ugly 404 and cordova seemed to work fine.

Edit: You can delete the code that does the ajax request all together from cordova and things would work just fine.

查看更多
欢心
5楼-- · 2020-02-07 20:27

It seems like a feature introduced in Cordova 2.6.0, at least I just noticed in this version. At this point I could not find any documentation and I don't have many details on it, but right now I solved the 404 issue adding a dummy cordova_plugins.json file to the root of my project.

As it expects a valid json file I added the following content to the file: "just a dummy file required by Cordova 2.6.0"

查看更多
狗以群分
6楼-- · 2020-02-07 20:28

Filip Maj of Adobe has said elsewhere that this is due to (so far) partially implemented plugin tooling. In future versions of Cordova, the plugin tooling will generate cordova_plugins.json itself.

For now, he has said it's save to completely ignore the 404 error. If you feel it is affecting your application, you should file a bug with Cordova.

[Note that if you add a dummy file yourself, it may affect the integration of Plugins]

查看更多
Luminary・发光体
7楼-- · 2020-02-07 20:32

i confirm francis answer and would note that on 2.7 if a dummy file is inserted, sometimes it starts an infinite loop on error "processMessage failed: invalid message:" (line cordova-2.7.0.js:971). keeping the 404 error seems indeed safer. (ref: https://groups.google.com/forum/?fromgroups#!topic/phonegap/slbvvtEw0aw)

查看更多
登录 后发表回答