Hacking on Chromium for Android from Eclipse (part 1)

In the Chromium Developers website has some excellent resources on how to setup an environment to build Chromium for Linux desktop and for Android. There’s also a detailed guide on how to setup Eclipse as your development environment, enabling you to take advantage of code indexing and enjoy features such as type hierarchy, call hierarchy, macro expansion, references and a lot of tools much better than the poor man’s trick of grepping the code.

Unfortunately, there are some integration aspects not covered by those guides, so joining all the dots is not a smooth task. In this series of posts, I’m going to explain the missing parts to setup a working environment to code and debug Chromium for Android from Eclipse, both C++ and Java code. All the steps and commands from this series of posts have been tested in an Ubuntu Saucy chroot. See my previous post on how to setup a chroot if you want to know how to do this.

Get the source code

See the get-the-code guide. Don’t try to reconvert a normal Desktop build into an Android build. It just doesn’t work. The detailed steps to get the code from scratch and prepare the dependencies are the following:

 cd ANDROID # Or the directory you want
 fetch --nohooks android --nosvn=True
 cd src
 git checkout master
 gclient sync --nohooks

Configure and generate the project (see AndroidBuildInstructions), from src:

 # Make sure that ANDROID/.gclient has this line:
 # target_os = [u'android']
 # And ANDROID/chromium.gyp_env has this line:
 # { 'GYP_DEFINES': 'OS=android', }
 gclient runhooks

Build Chrome shell, from src:

 # This builds
 ninja -C out/Release chrome_shell_apk
 # This installs in the device
 # Remember the usual stuff to use a new device with adb:
 # http://developer.android.com/tools/device.html 
 # http://developer.android.com/tools/help/adb.html#Enabling
 # Ensure that you can adb shell into the device
 build/android/adb_install_apk.py --apk ChromeShell.apk --release

If you ever need to update the source code, follow this recipe and use Release or Debug at your convenience:

 git pull origin master
 gclient sync
 # ninja -C out/Release chrome_shell_apk
 ninja -C out/Debug chrome_shell_apk
 # build/android/adb_install_apk.py --apk ChromeShell.apk --release
 build/android/adb_install_apk.py --apk ChromeShell.apk --debug

As a curiosity, it’s worth to mention that adb is installed on third_party/android_tools/sdk/platform-tools/adb.

Configure Eclipse

To configure Eclipse, follow the instructions in LinuxEclipseDev. They work nice with Eclipse Kepler.

In order to open and debug the Java code properly, it’s also interesting to install the ADT plugin in Eclipse too. Don’t try to reuse the Android SDK in “third_party/android_tools/sdk”. It seems to lack some things. Download a fresh standalone SDK from the official page instead and tell the ADT plugin to use it.

In the next post, I will explain how to debug C++ code running in the device, both from the command line and from Eclipse.


4 thoughts on “Hacking on Chromium for Android from Eclipse (part 1)”

  1. I found the following problem when running gclient runhooks:

    ________ running ‘/usr/bin/python src/build/gyp_chromium’ in ‘/home/jaragunde/chromium’
    Updating projects from gyp files…
    Traceback (most recent call last):
    File “src/build/gyp_chromium”, line 318, in
    gyp_rc = gyp.main(args)
    File “/home/jaragunde/chromium/src/tools/gyp/pylib/gyp/__init__.py”, line 525, in main
    return gyp_main(args)
    File “/home/jaragunde/chromium/src/tools/gyp/pylib/gyp/__init__.py”, line 501, in gyp_main
    params, options.check, options.circular_check)
    File “/home/jaragunde/chromium/src/tools/gyp/pylib/gyp/__init__.py”, line 129, in Load
    params[‘parallel’], params[‘root_targets’])
    File “/home/jaragunde/chromium/src/tools/gyp/pylib/gyp/input.py”, line 2744, in Load
    File “/home/jaragunde/chromium/src/tools/gyp/pylib/gyp/input.py”, line 607, in LoadTargetBuildFilesParallel
    parallel_state.pool = multiprocessing.Pool(multiprocessing.cpu_count())

    File “/usr/lib/python2.7/multiprocessing/synchronize.py”, line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
    OSError: [Errno 13] Permission denied

    The reason was the lack of access to the shared memory from inside my chroot, so make sure you have the following lines in your /etc/schroot/default/fstab:

    /dev/shm /dev/shm none rw,bind 0 0
    /run/shm /run/shm none rw,bind 0 0

  2. Another tip; if you want to build a previous version you will have to add ‘gclient revert’ to the recipe, so the proper branches for the dependent projects are gathered:

    git checkout 39.0.2171.93
    gclient revert
    gclient sync

  3. Hello

    Its about 2 years have passed when this post was posted.
    I was getting problem in building the Chromium for Android and this post made my life.

    Now I am successfull in making ChromeShell.apk but want ot build Full Browser APK.

    Please suggest me for this.

    1. I think that at the time I wrote the post it wasn’t possible to build the full browser, only ChromeShell. I don’t know if Google opened up their policy since then.

      In any case, I would suggest you to have a look at the most updated instructions posted in Chromium build instructions for Android and try to apply the strategies in the posts in order to have Eclipse working with the code if that’s what you want.

Leave a Reply

Your email address will not be published.