How to embed crosswalk-lite with ionic tutorial


#1

Hi, i’ve spent some days trying to reduce the apk size with crosswalk, and finally i made it so i want to share with the ionic community the way, i think is interesting to have a cross-android-version app that weights 10 MB less than the normal crosswalk .

First of all the reason why it always goes to download the normal binaries is that the crosswalk-lite is not in official release, but i had no problems with my app so here we go: Go to your project folder than edit this file:

platforms/android/cordova-plugin-crosswalk-webview/yourapp-xwalk.gradle

replace

repositories {
  maven {
    url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
  }
}

to be

repositories {
  mavenLocal()
}

then add near the line 71 after cdvPluginPostBuildExtras.add({:

def liteSpec = "org.xwalk:xwalk_core_library:1.0.0.1"

and edit the dependecies rule to be

dependencies {
        compile liteSpec
    }

remember that 1.0.0.1 is our self created version

Now download from the crosswalk-lite repository the version you want to embed, i have tested with the version 17.46.451.1 , download just the .aar file. This version has both x86 and armv7 reources so you have to unzip the .aar (is actually a zip file ) and then delete the file

res/raw/libxwalkcore.so.x86 [ if you want to make apk for armv7 devices ]

res/raw/libxwalkcore.so.armeabi_v7a [ if you want to make apk for x86 devices ]

this is because it will trigger the error duplicate resources, as i noticed.

Now zip again the folder without the resource and rename it to .aar

And finally the magic touch, (if you haven’t installed maven do apt-get install maven2)

mvn install:install-file -Dfile=*YOURFILE*.aar -DgroupId=org.xwalk -DartifactId=xwalk_core_library -Dversion=1.0.0.1 -Dpackaging=aar

Now you can build your app with the crosswalk-lite embbeded, it may seems difficult but it’s not , and it worth every mb saved to the apk


#2

It worked! I was trying to make it for a long time. Thank you so much.
You helped me a lot.


#3

Thanks! It’s been a while since I first tried something similar! Cheers!


#4

Thanks for sharing !
IONIC TEAM, UPDATE THE CLI !


#5

Thanks!
When app is launched for the first time,it shows a dialog with a cancel button. If you click cancel, the app would be crached. How to solve it?


#6

This is a fault of crosswalk-lite, i hope it will be fixed on the next releases.
At least it appears just in the first app start


#7

That is no longer applicable unfortunately, the later updated versions of crosswalk-lite no longer has the binaries in the res/raw folder.


#8

I built fine with the latest version (17.46.455.1) , yes the binares are no more in that folder, but they had split the aar file for both x86 and armv7 so the step of deleting one resource can be skipped , but it works :slight_smile:


#9

I can see that the later versions of .aar is still 21Mb, and there’s binaries in the jni folder…?

Can you clarify what are the steps to follow for the newer versions?

Actually, what you described,

the step of deleting one resource can be skipped

That is untrue, still a folder within the jni folder needs to be deleted.

And yes, I confirm that there’s a rather dialog box appears that is installing a ‘Crosswalk service’ on android, then the app starts, this is initial start up though.

PS: Be careful when re-zipping. The ionic build android will complain about the structure of the zip file with a rather misleading message “Error: ‘.’ is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore”


#10

as you can see from this repository you can find the aar file for each x86 and armv7, so you can now maven that file directly


#11

It looks like the next cordova-plugin-crosswalk-webview release (1.7.0) will contain a “lite” mode. I hope this release will come very soon.

https://crosswalk-project.org/jira/browse/XWALK-5095


#12

It’s now possible to embed xwalk-lite through ionic cli. The xwalk cordova plugin must be installed from the git repo, the update hasn’t been released yet to npm.

ionic plugin add https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview --variable XWALK_MODE="lite"

The extra variable with the “lite” flag is supposed to work through command line, but it hasn’t worked for me.

I have modified manually the config.xml file:

<preference name="xwalkVersion" value="xwalk_core_library_canary:17+" />
<preference name="xwalkMode" value="lite" />

The “xwalk_core_library_canary:17+” version si needed because xwalk-lite is yet in “canary” state, and the last released versions are 17.x.

After building the ionic “tabs” starter project, the generated apks’ size is 14.5MB(arm) and 16MB(x86).

I thought the size would be reduced a bit more, but it’s better than nothing.


#13

Hey @jonmikelm,

Do you know if this generated arm version can run on X86 devices (is armabi-v7a?)

Thanks,


#14

I installed crosswalk lite and it is working fine with reduced app size. But for the first time installation it is showing me one confirm box.
Can anybody tell if it can be disabled or customisable or replaceable with a loader.


#15

i got the same issue for the first time, accurding to this issue in crosswalk-project the download popup is necessary to decompress lite library.