Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active May 24, 2018 05:24
Show Gist options
  • Save nolanlawson/f332ed32202fe3671769 to your computer and use it in GitHub Desktop.
Save nolanlawson/f332ed32202fe3671769 to your computer and use it in GitHub Desktop.
Helper script to convert an Ionic/Cordova app to a Crosswalk app

Convert a Cordova/Ionic project to a Crosswalk project

Converts an existing Cordova/Ionic project to a Crosswalk project. When the script is done running, you should have a fat 40MB APK file in platforms/android/ant-build.

This assumes you have the following already installed: cordova, ant, android, and that your ANDROID_HOME is set to point to the Android SDK.

This will work on both x86 and ARM. If you want to build two separate APKs so that they're smaller, then modify the script; the script at least shows how it works.

Step 1: download the "Cordova Android" libraries from the Crosswalk downloads page. You don't need anything except for the "Cordova Android" ones.

Step 2 Unzip them both.

Step 3 Navigate to your project directory and run:

./prepare_crosswalk \
  /path/to/crosswalk-cordova-VERSION-x86 \
  /path/to/crosswalk-cordova-VERSION-arm

Then run either:

ionic build android # for ionic

or

cordova build android # for cordova

Thanks to this article for figuring out how to get this to work.

#!/usr/bin/env bash
#
# usage: provide a path to a crosswalk-cordova-x86 and crosswalk-cordova-arm library,
# run in the current (project) directory, and it will set up crosswalk for you
#
# ./prepare_crosswalk.sh /path/to/crosswalk-cordova-VERSION-x86 /path/to/crosswalk-cordova-VERSION-arm
#
X86=$1
ARM=$2
if [[ -z $X86 ]]; then
echo 'usage: ./prepare_crosswalk /path/to/crosswalk-cordova-VERSION-x86 /path/to/crosswalk-cordova-VERSION-arm'
exit 1
fi
if [[ -z $ARM ]]; then
echo 'usage: ./prepare_crosswalk /path/to/crosswalk-cordova-VERSION-x86 /path/to/crosswalk-cordova-VERSION-arm'
exit 1
fi
cordova platform rm android
cordova platform add [email protected]
rm -fr platforms/android/CordovaLib/*
cp -a $X86/framework/* platforms/android/CordovaLib/
cp -a $ARM/framework/xwalk_core_library/libs/armeabi-v7a platforms/android/CordovaLib/xwalk_core_library/libs/
cp $X86/VERSION platforms/android/
cd platforms/android/CordovaLib/
android update project --subprojects --path . --target "android-19"
ant debug
cd -
# sed sucks on a mac, can't do sed -i
cat platforms/android/AndroidManifest.xml | sed 's/<\/manifest>/ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" \/>; <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" \/>;<\/manifest>/' > platforms/android/AndroidManifestNew.xml
# sed doesn't play nice with newlines either, so...
tr ';', '\n' < platforms/android/AndroidManifestNew.xml > platforms/android/AndroidManifest.xml
rm -f platforms/android/AndroidManifestNew.xml
@eskibars
Copy link

eskibars commented Dec 4, 2014

You should change line 23 to "cordova platform add [email protected]" instead. 9.38.208.10 is now stable and based on 3.5.1 and cordova @ 3.5 has a high security issue: http://cordova.apache.org/announcements/2014/08/04/android-351.html

@slj
Copy link

slj commented Dec 11, 2014

Great script Nolan!

For nicer formatting at the end, I would replace the last 2 lines with:

cat platforms/android/AndroidManifest.xml | sed 's/<\/manifest>/    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" \/>;    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" \/>;<\/manifest>/' > platforms/android/AndroidManifestNew.xml
# sed doesn't play nice with newlines either, so...
tr ';', '\n' < platforms/android/AndroidManifestNew.xml > platforms/android/AndroidManifest.xml
rm -rf platforms/android/AndroidManifestNew.xml

@nolanlawson
Copy link
Author

@eskibars @slj done. thanks!

@jnishiyama
Copy link

@nolanlawson Thank you for this! It is the only thing that worked for me. I would add that the relevant Cordova version is 3.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment