Developing with Crosswalk AAR
The Crosswalk AAR bundle is the binary distribution of the xwalk_core_library and includes both x86 and armv7 architectures. A developer no longer needs to download the crosswalk-webview bundle manually but can specify a version code using either the Gradle or Maven projects.
Set up host
Install JDK
Gradle requires JDK version 6 or higher. The JAVA_HOME environment variable must be set to the correct JDK installation directory.
$ export JAVA_HOME=<path to JDK>
Install the Android SDK
Download the Android SDK from http://developer.android.com/sdk/index.html.
Extract the SDK from the archive file you downloaded.
Add the Android SDK directories to your PATH:
$ export PATH=<path to Android SDK>:$PATH $ export PATH=<path to Android SDK>/tools:$PATH $ export PATH=<path to Android SDK>/platform-tools:$PATHIn the SDK Manager window, select the following items from the list:
[ ] Tools [x] Android SDK Platform-tools 19.0.1 [x] Android SDK Build tools 18.0.1 [ ] Android 4.3 (API 18) [x] SDK PlatformNote: if you are using devices with versions of Android later than 4.3, you should also install the
platform tools,build toolsandSDK platformfor those versions.
Develop With the Gradle Project
Install Gradle
Download a recent version of the
gradlebinary (~40MB): http://www.gradle.org/downloads/Unzip it:
$ unzip gradle-<version>-bin.zipFor convenience, add the
gradlebinary to your PATH environment variable:$ export PATH=$PATH:<path to gradle>/bin
Develop With Maven Project
Install Maven
Download Maven from http://maven.apache.org/download.cgi. Version 3.2.2 is known to work.
Unzip it:
$ tar -zxvf apache-maven-3.2.2-bin.tar.gzSet the Maven enviroment variables to point to the install directory:
$ M2_HOME=/path/to/apache-maven-3.2.2 $ export MAVEN_OPTS="-Xms256m -Xmx512m" $ export PATH=$M2_HOME/bin:$PATH
Install Maven Android SDK Deployer
Checkout Maven Android SDK deployer from git
$ git clone git@github.com:mosabua/maven-android-sdk-deployer.gitUse the Maven Android SDK deployer to install the Maven components for Android 4.4*:
$ cd maven-android-sdk-deployer $ mvn install -P 4.4
Install Maven Android Plugin
Checkout Maven Android Plugin from git
$ git clone git@github.com:jayway/maven-android-plugin.gitInstall Maven Android Plugin into your local Maven repository
$ cd maven_android_plugin $ mvn clean install
Crosswalk AAR Version
The AAR remote Maven repository is https://download.01.org/crosswalk/releases/crosswalk/android/maven2/. Versions are available for stable and beta. If you need the canary version you can download it:
$ wget https://download.01.org/crosswalk/releases/crosswalk/android/canary/9.38.207.0/crosswalk-9.38.207.0.aar
Then install it into the local Maven repository:
$ mvn install:install-file -DgroupId=org.xwalk -DartifactId=xwalk_core_library_canary \
-Dversion=9.38.207.0 -Dpackaging=aar -Dfile=crosswalk-9.38.207.0.aar \
-DgeneratePom=true
Create and Build your Android project with Crosswalk AAR
Create Android Project with the Crosswalk embedding APIs.
Refer to the section in the Embedding Crosswalk article called Add code to integrate the webview.
The reference to Maven repo in build.gradle will look like:
Repositories { Maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2' } }Use
mavenLocal()instead of the remote repo url to refer to the local aar:Repositories { mavenLocal() }The dependency (a reference) to the AAR library will look like (9.38.208.8 is a crosswalk version):
Dependencies { Compile 'org.xwalk:xwalk_core_library_beta:9.38.208.8' }The latest AAR need set compileSdkVersion to 21 in build.gradle file.
Gradle places the AAR library in its project directory:
~/.gradle/caches/modules-2/files-2.1/
Support different CPU architectures with each APK (such as for ARM, x86).
A product flavor defines a customized version of the application build by the project. We can have different flavors which generate apk for each architecture.
android { ... productFlavors { armv7 { ndk { abiFilters "armeabi-v7a", "" } } x86 { ndk { abiFilters "x86", "" } } } }Get the version code from the manifest. Add an extra digit to the end of the version code which implicity specifies the architecture. The x86 final digit is 4, arm is 2.
versionCode manifest.versionCode + 4Build your project with Gradle, the following commands will build the corresponding arch apk in build/apk directory.
$ gradle assemblex86 $ gradle assemblearmv7Use
$ gradle buildto build both arm and x86 APKs at once.
Build with Maven
The Maven android plugin has a known issue that it can't build multiple APKs for different architectures automatically. We need to specify x86/arm aar in classifier. You can try to test from the sample
Create Maven Project
Create Android Project with the Crosswalk webview APIs.
Refer to the section in the Embedding Crosswalk article called Add code to integrate the webview.
The reference to the remote repo in pom.xml will look like:
<repositories> <repository> <id>01-org</id> <name>o1 org repo</name> <url>https://download.01.org/crosswalk/releases/crosswalk/android/maven2</url> <layout>default</layout> </repository> </repositories>The dependency (a reference) to the x86 AAR library in pom.xml will look like:
<dependency> <groupId>org.xwalk </groupId> <artifactId> xwalk_core_library_beta</artifactId> <version>9.38.208.8</version> <classifier>x86</classifier> <typr>aar</type> </dependency>If you want to use arm AAR in your Maven project, you can set classifier to arm:
<classifier>arm</classifier>Maven will download the AARs automatically into project repository:
~/.m2/repository/Support multiple APKs
Build different APKs using 'Build profile'
A Build profile is a set of configuration values which can be used to set or override default values of Maven build.
<profile> <id>x86</id> </profile>Execute the following mvn command. Pass the profile name as argument using -P option.
$ mvn install -Px86Update manifest versioncode and versionname. Refer to stackoverflow
android-maven-plugin support resource filtering to update manifest.
Modify AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.xwalkEmbedd" android:versionCode="${app.version.code}" android:versionName="${app.version.name}" >Set versioncode and versionname.
arm profile:
<app.version.code>1.0.0.2</app.version.code> <app.version.name>1.0.0-SNAPSHOT</app.version.name>x86 profile:
<app.version.code>1.0.0.4</app.version.code> <app.version.name>1.0.0-SNAPSHOT</app.version.name>Filter manifest and put filtered file in target/filtered-manifest:
<resource> <directory>${project.basedir}</directory> <filtering>true</filtering> <targetPath>${project.build.directory}/filtered-manifest</targetPath> <includes> <include>src/main/AndroidManifest.xml</include> </includes> </resource> ... <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <extensions>true</extensions> <configuration> <undeployBeforeDeploy>true</undeployBeforeDeploy> <!-- tell build process to use filtered manifest --> <androidManifestFile>${project.build.directory}/src/main/filtered-manifest/AndroidManifest.xml</androidManifestFile> </configuration> </plugin> ...Output different name to apk:
<finalName>${project.artifactId}-${project.version}-${profile-id}</finalName> <profile-id>x86</profile-id> <profile-id>arm</profile-id>
Build your project with Maven, the following commands will build the corresponding arch apk in target/ directory:
$ mvn clean install -Px86 $ adb install ./target/xwalk-aar-example-1.0.0-SNAPSHOT-x86.apk $ mvn clean install -Parm $ adb install ./target/xwalk-aar-example-1.0.0-SNAPSHOT-arm.apk
Samples
You can get the sample of using Crosswalk runtime library with Android Studio in crosswalk-samples. An sample using classifier AAR with Maven you can get from xwalkEmbed-Maven.tar.gz.
After downloading, unzip it from the command line:
$ tar -xzvf xwalkEmbed-Maven.tar.gz
English
