Android 集成Chrome 浏览器内核 Crosswalk
# Crosswalk 内核的兴起与消亡
Android 4.4 版本之前,使用的是基于 androidWebKit 的 WebView
但实际上,由于 Android 的碎片化问题(大量存在不同的 Android 系统版本,并且各个厂商对内置应用进行定制化,有可能用的不是最新的浏览器内核)。这就导致 WebView 在真实环境中对 API 的支持根本无迹可寻,越发混乱。
# Android 碎片化问题集中表现在下面几个方面:
- 设备繁多,硬件配置参差不弃,设备性能各异,差距很大
- 品牌众多,厂商标准不一致,定制化系统体验不同
- 版本各异,国内外系统环境差异巨大
- 分辨率不统一,各种类型尺寸众多
随着混合开发的兴起,前端对 API 的支持程度和网页的表现效果都有了更严格的要求,原生WebView 由于碎片化严重,API支持程度未知,容易引发很多意料之外的BUG。
# 这时候,就诞生了一些第三方浏览器内核
Intel 开源的基于 Chrome 的 Crosswalk 内核 和 XWalkView 浏览器(2017年5月停止维护) https://github.com/crosswalk-project/crosswalk https://github.com/tenta-browser/crosswalk
腾讯出品的 X5 浏览器内核 https://x5.tencent.com/tbs/sdk.html
从 Android 5.0 开始,Google 把 Chromium blink内核 webview 作为 apk 单独从系统抽离出去,可以在应用市场(Google Play)上面接收安装更新。应用可以直接使用该webview内核,Google也可以及时发布更新,不用再通过更新系统才能更新浏览器内核,也避免部分了 Android 系统碎片化问题。
因此 Intel 的 Crosswalk 就停止维护了。然而由于国内被墙,并没有接入谷歌服务,因此 腾讯X5 内核 还流传至今,并且被广泛的应用
代码初始化
点击查看js调用安卓的代码
class mixture {
/*跳转到设置页*/
DxstartActivity() {
window.Plusdx.DxstartActivity()
}
/*跳转到IP设置页*/
DxstartActivityIP() {
window.Plusdx.DxstartActivityIP()
}
/*跳转到Wift设置页*/
DxstartActivityWift() {
window.Plusdx.DxstartActivityWift()
}
/*打开相机*/
OpenXJ() {
window.Plusdx.OpenXJ()
}
/*打开相机*/
tetMusc() {
window.Plusdx.tetMusc()
}
/*更新*/
shengji(url) {
window.Plusdx.shengji(url)
}
/**
获取系统ip
this.getUserIP(function(ip){
th.ipse = ip
})
*/
getUserIP(onNewIP) { // onNewIp - your listener function for new IPs
//compatibility for firefox and chrome
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new myPeerConnection({
iceServers: []
}),
noop = function () {},
localIPs = {},
ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g
function iterateIP(ip) {
if (!localIPs[ip]) onNewIP(ip);
localIPs[ip] = true;
}
//create a bogus data channel
pc.createDataChannel("");
// create offer and set local description
pc.createOffer().then(function (sdp) {
sdp.sdp.split('\n').forEach(function (line) {
if (line.indexOf('candidate') < 0) return;
line.match(ipRegex).forEach(iterateIP);
});
pc.setLocalDescription(sdp, noop, noop);
}).catch(function (reason) {
console.log(reason)
});
//listen for candidate events
pc.onicecandidate = function (ice) {
if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
};
}
/*横竖屏切换 0横屏 1竖屏*/
screenWwitch(ty) {
window.Plusdx.screenWwitch('' + ty)
}
}
export default new mixture().__proto__
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77