Tag Archives: cordova

How to Solve Cordova integrates Gaode Map key error

Plug in: com.kit.cordova.amaplocation

https://www.jianshu.com/p/85aceaee3b35

When referring to the above link articles or other articles, we still can’t solve the key error of Gaode
running the following two commands may solve the long-standing problem

cordova platform remove "platformName" // Remove the project platform
cordova platform add "platformName" // add device platform

Example:

cordova platform remove android // Remove Android project platform
cordova platform add android // add android device platform

[Error] because it violates the following Content Security Policy directive

[Error] because it violates the following Content Security Policy directive

In the process of HTML development, we encountered the following error, which means the permission problem of HTML meta setting

Refused to connect to 'blob:http://localhost:8080/6d57f07f-3c2f-49ca-be30-fd0b7f4cff6e' 
because it violates the following Content Security Policy directive: 
"default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content: ". 
Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.

Specifically, this bug appears when using vue-html2pdf.
The screenshot is as follows

the last time I encountered a similar problem was when I used the video tag.
These are similar problems

You need to open the source code of the HTML page (for example, index.html ), modify the meta in the head section

  <meta http-equiv="Content-Security-Policy" content="default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content: https://ssl.gstatic.com; 
    media-src * blob: 'self' http://* 'unsafe-inline' 'unsafe-eval'; 
    style-src * 'self' 'unsafe-inline'; 
    img-src * 'self' data: content:; 
    connect-src * blob:;">

The example is divided into multiple lines and can be modified according to your own needs. For example, IMG SRC allows * and other types of resources.
Connect SRC allows * blob: and other types of resources. Note that * does not contain the blob: type. If it is not declared, blob: may be wrong

reference material

Used to connect to XXX – because it violates the following content security policy
Cordova rejected to connect to xxxxx - white list refuses to send network requests
meta tag official website: https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/meta
Content security policy website: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy__ by_ cnvoid

How to solve the problem of requirements check failed for JDK 8 when Cordova 9.0 is built

the economy of the motherland is recovering, and people of all ethnic groups are actively engaged in the task of restoring production. As a codemaker, I have also been nervous for a long time. Recently, I have been busy with several projects, including an app, which needs to be quickly set up for preview and test, so I directly listed Cordova. However, I am surprised to step on it.

, there’s nothing wrong with building the project, it just came to me during the build:

Requirements check failed for JDK 8 ('1.8.*')! Detected version:11.0.7

Check your ANDROID_SDK_ROOT/JAVA_HOME/PATH environment variables.

indicates clearly that jdk11 does not match the required jdk8 for cordova. The reason is also clear, as the native environment was upgraded from JDK8 to JDK11 a while ago.

the problem now is that I don’t want to change java_home back to 8, because all the compiled versions of all the items on the machine have changed to jdk11, which would take me half a day to fix. (and a lot of history projects in Eclipse)

I use [email protected], which was released a year ago, but the latest cordova10 in NPM, which is still at nightly (compiled daily), is not even rc and is obviously not recommended in a production environment. In other words, Cordova9 is the latest stable edition, so I can’t expect to change the status quo by upgrading Cordova9.

also tried to set java.home in IDE (vscode), but it was useless. This setting is only valid for the Java plug-in of VSC, but it is incapable of cordova.

after many thoughts, if cordova cannot be surrendered, I will have to fall back to jdk8.

since cordova is based on nodejs, it occurs to me that all the hints should be in the clear text code. So a hard-hearted search keyword Requirements check failed for the whole project.

is actually retrieved:

in platforms/android cordova/lib/check_reqs js files in the module. Exports. The run method, related to the one and only one place!

and it says:

// Returns a promise.
module.exports.run = function () {
    return Q.all([this.check_java(), this.check_android()]).then(function (values) {
        console.log('Checking Java JDK and Android SDK versions');
        console.log('ANDROID_SDK_ROOT=' + process.env['ANDROID_SDK_ROOT'] + ' (recommended setting)');
        console.log('ANDROID_HOME=' + process.env['ANDROID_HOME'] + ' (DEPRECATED)');

        if (!String(values[0]).startsWith('1.8.')) {
            throw new CordovaError(
                'Requirements check failed for JDK 8 (\'1.8.*\')! Detected version: ' + values[0] + '\n' +
                'Check your ANDROID_SDK_ROOT/JAVA_HOME/PATH environment variables.'
            );
        }

        if (!values[1]) {
            throw new CordovaError('Requirements check failed for Android SDK! Android SDK was not detected.');
        }
    });
};

sees the 1.8 criterion, and the check_java method also makes it clear that the Java environment is being judged. So the “1.8.” directly changed to “11.”, and the compilation passed smoothly.

postscript:

first of all, I do not recommend arbitrary changes to the dependent framework source code, which will not only affect subsequent updates to the framework, but also cause unknown exceptions. But there is no way, this is only a temporary solution.

I don’t know if cordova9 has a key piece that relies only on jdk8, and I don’t know what effect jdk11 will have on cordova9, but I do think it’s clear that if you want to minimize the impact by changing one piece of code, the impact is really small.