Crosswalkは、Androidで使用されるのWebViewに代わるWebランタイムです。 Crosswalkは、Google Chromiumをベースにしています。 なぜWebViewを使わず、Crosswalkを使うのか? WebViewは、各Android OSのバージョンによって大きく異なります。 そのため、私は両者の違いの多くの問題に衝突しました。 Crosswalkを使用すれば、すべてのAndroid OSのバージョン間で一貫性のあるWebViewで作業することができます。 それに加えて、それは、より良いHTML5をサポートしています。 その理由はこちらの記事を見てください「なぜ、AndroidのためのCrosswalkを使うか?」
あなたのアプリケーションでCrosswalkを埋め込むための命令は、ADTに基づいており、複雑になります。 あなたがmaven2リリースを使うならば、CrosswalkをAndroid Studioに加えることは非常に簡単です。
Android Studioで新しいAndroidアプリケーションを作成し、Crosswalkを埋め込むための手順は次のとおりです。
新しいAndroidプロジェクトを作成します。 メニューから「File > New Project」を選択します アプリケーションの名前を「 CrosswalkDemo 」と付けます。 ドメインとプロジェクトの場所を追加して「Next」を押します。 「Phone and Tablet」を選択、最小SDK 「API 19」を選択して「Next」を押します。 「Blank Activity」を選択して「Next」を選択します。 デフォルトのアクティビティ名を使用して「Finish」を押します。 Crosswalk設定
あなたがインストールするCrosswalkのリリースを識別します。ここで最新リリースを見つけることができます。 https://download.01.org/crosswalk/releases/crosswalk/android/maven2/
このデモのために私はここで発見されたバージョン10.39.235.15を選択します。
Open the file:
CrosswalkDemo/app/build.gradle
Mavenのリポジトリを追加する必要があります。
1
2
3
4
5
|
repositories { maven { } } |
Then add this to your dependencies:
1
|
compile 'org.xwalk:xwalk_core_library:10.39.235.15' |
The finished file should look like:
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
|
apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "20.0.0" defaultConfig { applicationId "org.diego.android.crosswalkdemo" minSdkVersion 19 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } repositories { maven { } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.0' compile 'org.xwalk:xwalk_core_library:10.39.235.15' } |
Update the Code
Add an XWalkView to your layout like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:background = "#000000" > < org.xwalk.core.XWalkView android:id = "@+id/xwalkWebView" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:background = "#000000" /> </ LinearLayout > |
In your activity, find the XWalkView and then load a url like:
1
2
|
xWalkWebView=(XWalkView)findViewById(R.id.xwalkWebView); |
That’s pretty much it.
The entire activity looks like:
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
|
package org.diego.android.crosswalkdemo; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import org.xwalk.core.XWalkPreferences; import org.xwalk.core.XWalkView; public class MainActivity extends ActionBarActivity { private XWalkView xWalkWebView; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); xWalkWebView=(XWalkView)findViewById(R.id.xwalkWebView); // turn on debugging XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true ); } @Override protected void onPause() { super .onPause(); if (xWalkWebView != null ) { xWalkWebView.pauseTimers(); xWalkWebView.onHide(); } } @Override protected void onResume() { super .onResume(); if (xWalkWebView != null ) { xWalkWebView.resumeTimers(); xWalkWebView.onShow(); } } @Override protected void onDestroy() { super .onDestroy(); if (xWalkWebView != null ) { xWalkWebView.onDestroy(); } } } |
You can download a sample project here:
https://github.com/dougdiego/CrosswalkDemo
More details about the AAR Crosswalk release can be found here:
https://crosswalk-project.org/documentation/embedding_crosswalk/crosswalk_aar.html