科尔多瓦“释放"行为与“调试"不同关于 SSL [英] cordova "release" behaves differently to "debug" regarding SSL
问题描述
我在使用cordova时遇到了非常困难且完全无法搜索的问题.
I have very difficult and totally ungoogleable problem with cordova.
在--debug
模式下编译运行良好的程序,在--release
模式下编译后停止工作.我确保来源是相同的,并且效果是恒定的.
A program, working perfectly being compiled in --debug
mode, ceases working after compilation in --release
mode.
I made sure the source is identical, and the effect is constant.
--debug
构建和 --release
构建之间的唯一区别是 --release
构建无法打开任何 SSL 连接.
The only difference between --debug
build and --release
build is that the --release
build fails to open any SSL connections.
这个问题的范围很窄,在我的例子中是以下几行:
This problem is localized very narrow, in my case it is the following line:
Socket = new WebSocket('wss://376.su/');
我的一个朋友在行中报告了同样的错误:
a friend of mine has reported the same error occurrence in the line:
<img src="https://blabla" />;
UPD:问题已解决,见答案.
UPD: the problem is solved see the answers.
推荐答案
问题
我已经确定了问题的确切根源,并且找到了完美的解决方案.结果证明这是两个独立问题的叠加,每个问题都具有严重的误导性:
Problem
I have identified the exact source of the problem and i have found the perfect solution. It turned out to be a superposition of two separate issues each of which is seriously misleading:
我从 Thawte 获得的 SSL 证书(尽管成本很高)未被 Android 5.1.1 识别为有效证书(但被所有桌面浏览器识别)
My SSL certificate from Thawte (despite its cost) is not recognized by Android 5.1.1 as a valid one (while being recognized by all desktop browsers)
cordova build
中的 --debug
标志只是忽略证书错误";(默默地).
The --debug
flag in cordova build
simply ignores certificate "errors" (silently).
解决方案
转到您的项目目录并找到以下文件:
Solution
Go to your project's directory and find the following file:
platforms/android/CordovaLib/src/org/apache/cordova/engine/SystemWebViewClient.java
找到方法定义(onReceivedSslError
)和以下条件:
Locate the method definition (onReceivedSslError
) and the following condition:
(appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
这就是 --debug
和 --release
的不同之处.为了忽略证书错误"应执行以下代码:
This is what makes --debug
and --release
different.
In order to ignore certificate "errors" the following code should be executed:
handler.proceed();
return;
这个文件在构建过程中一直存在.下次向项目添加平台时,不要忘记忽略这些准错误.
This file persists through the build process. Don't forget to ignore those quasi-errors next time you add a platform to your project.
这篇关于科尔多瓦“释放"行为与“调试"不同关于 SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!