Skip to content

Instantly share code, notes, and snippets.

@pwnall
Last active December 14, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwnall/5077076 to your computer and use it in GitHub Desktop.
Save pwnall/5077076 to your computer and use it in GitHub Desktop.
Step-by-step instructions for setting up a VM that builds Chrome for Android

Build Instructions for libchromewebview.so

This document contains step-by-step instructions for building a Chromium-powered Android WebView.

Chromium's build process is a bit fussy, and the Android target is even more fussy, so the least painful way of getting it done is to set up a VM with the exact software that the build process was designed for. The steps below accomplish this.

  1. Get the 64-bit ISO for Ubuntu Server 12.10.

  2. Set up a VirtualBox VM.

    • Name: ChromeWebView
    • Type: Linux
    • Version: Ubuntu 64-bit
    • RAM: 4096Mb
    • Disk: VDI, dynamic, 40Gb
  3. Change the settings (Machine > Settings in the VirtualBox menu)

    • System > Processor > Processor(s): 4 (number of CPU cores on your machine)
    • Audio > uncheck Enable Audio
    • Network > Adapter 1 > Advanced > Adapter Type: virtio-net
    • Network > Adapter 2
      • check Enable network adapter
      • Attached to > Host-only Adapter
      • Advanced > Adapter Type: virtio-net
    • Ports > USB > uncheck Enable USB 2.0 (EHCI) Controller
  4. Start VM and set up the server.

    • Select the Ubuntu ISO downloaded earlier.
    • Start a server installation, providing default answers, except:
      • Hostname: crbuild
      • Full name: crbuild
      • Username: crbuild
      • Password: crbuild
      • Confirm using a weak password
      • Encrypt home directory: no
      • Partitioning: Guided - use entire disk (no LVM or encryption)
      • Software to install: OpenSSH server
  5. After the VM restarts, set up networking.

    • Log in using the VM console.
    • Open /etc/network/interfaces in a text editor (sudo vim ...)
    • Duplicate the "primary network interface" section
    • In the duplicate section, replace-all eth0 with eth1, primary with secondary
    • Save the file.
    • sudo apt-get install -y avahi-daemon
    • sudo reboot
  6. Prepare to SSH into the VM.

    • If you don't have an ssh key
      • ssh-keygen -t rsa
      • press Enter all the way (default key type, no passphrase)
    ssh-copy-id crbuild@crbuild.local
    ssh crbuild@crbuild.local
    sudo sh -c "echo crbuild ALL=NOPASSWD: ALL >> /etc/sudoers"
  7. Install Depot Tools.

    sudo apt-get update && sudo apt-get -y upgrade
    sudo apt-get -y install git
    git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    echo "export PATH=$PATH:$HOME/depot_tools" >> ~/.bashrc
    source ~/.bashrc
  8. Get the Oracle Java 6 JDK.

    exit  # Get out of the VM ssh session, run this on the host.
    scp ~/Downloads/jdk-6u*-linux-x64.bin crbuild@crbuild.local:~/jdk6.bin
    ssh crbuild@crbuild.local  # Get back into the VM ssh session.
    sudo mkdir /usr/lib/jvm
    cd /usr/lib/jvm
    sudo /bin/sh ~/jdk6.bin -noregister
    rm ~/jdk6.bin
    sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_*/bin/javac 50000
    sudo update-alternatives --config javac
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_*/bin/java 50000
    sudo update-alternatives --config java
    sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_*/bin/javaws 50000
    sudo update-alternatives --config javaws
    sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.6.0_*/bin/javap 50000
    sudo update-alternatives --config javap
    sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_*/bin/jar 50000
    sudo update-alternatives --config jar
    cd ~/
  9. Get the Chromium source code and dependencies.

    # ssh crbuild@crbuild.local
    sudo apt-get install -y subversion
    sudo apt-get install -y ia32-libs libc6-dev-i386 g++-multilib
    mkdir ~/chromium
    cd ~/chromium
    gclient config https://src.chromium.org/chrome/trunk/src \
        https://commondatastorage.googleapis.com/chromium-browser-continuous/Linux/LAST_CHANGE 
    svn ls https://src.chromium.org/chrome  # Permanently accept the SSL certificate, if necessary.
    echo "target_os = ['android']" >> .gclient
    gclient sync --nohooks
    sudo ./src/build/install-build-deps-android.sh
    sudo ./src/build/install-build-deps.sh  # Debugging symbols are not necessary.
    . build/android/envsetup.sh  # There is no / between . and build.
    gclient runhooks
  10. Build the Chromium library.

    # ssh crbuild@crbuild.local
    cd ~/chromium/src
    . build/android/envsetup.sh  # There is no / between . and build.
    android_gyp
    ninja -C out/Release -j4 content_shell_apk  # Number of CPU cores after -j.
    ninja -C out/Release -j4 chromium_testshell  # Number of CPU cores after -j.
    ninja -C out/Release -j4 libwebviewchromium  # Number of CPU cores after -j.

Update and Rebuild Instructions

# ssh crbuild@crbuild.local
sudo apt-get update && sudo apt-get -y dist-upgrade
cd ~/chromium/
gclient sync
cd ~/chromium/src
. build/android/envsetup.sh  # There is no / between . and build.
android_gyp
ninja -C out/Release -j4 content_shell_apk  # Number of CPU cores after -j.
ninja -C out/Release -j4 chromium_testshell  # Number of CPU cores after -j.
ninja -C out/Release -j4 libwebviewchromium  # Number of CPU cores after -j.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment