Skip to main content

Clutter on Android: first results

With the release of Android 2.3, there's a decent way to integrate native applications with the NativeActivity class, an EGL library, and some C API to expose events, main loop, etc. So? how about porting Clutter to it now that it looks actually feasible? After a few days of work, the first results are there, quite promising!

There's still a fairly large number of items in my TODO before being happy with the state of this work, the most prominent items are:
  • Get a clean up pass done to have something upstreamable, this includes finishing the event integration (it receives events but not yet forward them to Clutter),
  • Come up with a plan to manage the application life cycle and handle the case when Android destroys the EGL surface that you were using (probably by having the app save a state, and properly tear down Clutter).,
  • While you probably have the droid font installed in /system/fonts, this is not part of the advertised NDK interface. The safest choice is to embed the font you want to use with your application. Unfortunately fontconfig + freetype + pango + compressed assets in your Android package don't work really well together. Maybe solve it at the Pango level with a custom "direct" fontmap implementation that would let you register fonts from files easily?
  • What to do with text entries? show soft keyboard? Mx or Clutter problem? what happens to the GL surface in that case?
  • Better test the GMainLoop/ALooper main loop integration (esp. adding and removing file descriptors),
  • All the libraries that Clutter depends on are linked into a big .so (which is the Android NDK application). It results in a big .so (~5 MB, ~1.7 MB compressed in the .apk). That size can be dramatically reduced, sometimes at the expense of changes that will break the current API/ABI, but hell, you'll be statically linking anyway,
  • Provide "prebuilt libraries", ie. pre-compiled libraries that makes it easy to just use Clutter to build applications.


  1. Hi!

    Your clutter port looks very nice. But i didn't found the source in the git-repositories. Would you release it?


  2. Hey, I haven't touched the port since that post. However I have a talk at the Desktop Summit in a week and I do intend to have a "preview" release for people to play with. Stay tuned!

  3. Do you think clutter has to use the NDK, or would it be possible to port the whole lot over to Java and use Dalvik?

  4. @Patrick: For now, it's NDK only. It's possible to make it work from the Java side, it's quite a lot of work though.

  5. Hi,

    I have downloaded your code , and tried that to create .so file using ndk-build command but it is failed to build.
    As it is not finding clutter modules in NDK , how i need to provide clutter modules to it.

  6. @Vishal
    do this:

    export NDK_MODULE_PATH=/clutter-android-prebuilts

    you can test with:

    $ cd /cogl-1.9.2/example/android/hello
    $ /ndk-build


  7. sduclos :
    do this:
    export NDK_MODULE_PATH=/clutter-android-prebuilts
    you can test with:
    $ cd /cogl-1.9.2/example/android/hello
    $ /ndk-build

    do this:

    export NDK_MODULE_PATH=\/clutter-android-prebuilts

    you can test with:

    $ cd \/cogl-1.9.2/example/android/hello
    $ \/ndk-build

  8. @Vishal
    my previous post is missing "your_path_to" in the 3 path above to convey that you need the full path

  9. @sduclos

    Hi sduclos ,

    I have tried your above way but still the code is jni is not compiling i am getting some errors and it is not compiling..

  10. Can you make available for download?

  11. @Vishal
    Sorry to be late,

    clutter-android-prebuilts is already compiled

    To compile 'hello' in cogl source tree 'cd' to it and run 'ndk-build'

    You need to set NDK_MODULE_PATH to the path of clutter-android-prebuilts before
    running the build.

    You should get a .so in libs/

  12. Hi Damien,
    Great work! I would like to test it and eventually contribute with some lines. Could you make it available for download?

    Thanks a lot!

  13. Well I find the ohand sample from your git repo. Now, as @Vishal pointed it's complaining about missing NDK_MODULE_PATH. So, how did I get my own clutter-android-prebuilt? How can I compile clutter so I can provide ndk-build with the missing module? @diega

  14. Hey!
    finally got it working :) sorry for the comments flood (u can remove the old ones if u want).
    The funny thing is that it loads the app nice in my ICS Tablet but it doesn't animate :) I just see the Hand static in the middle.

  15. @diega w00t! you're probably the second person in the world to have that working :) Having the hand static is the intended behaviour for Be aware that the prebuilt binaries provided were ultra alpha quality, using OpenGL ES1. It will fall appart if you try to use it.

    A good way to carry on this project today would be to:
    1/ build cogl with (the cogl part of my work here has been upstreamed and then made to work again by Robert Bragg)
    2/ port the clutter patches to 1.10
    3/ debug the result

  16. Hi Damien.

    First off, thanks a lot for this post - without it, I'd be much more hesitant to start what I'm starting now with Clutter on Android.

    I'd like to build Clutter myself, using a standalone toolchain. I'm going to build each of its dependencies one by one for different API levels, ABIs and with/without NEON. Did you go through a similar process to get your results? Any blockers/traps I should prepare to?

    Also, what do you know about building/running Clutter on iOS?

  17. guofeng.routon20 June 2012 at 07:49

    Hello,I want to know how to make "Maybe solve it at the Pango level with a custom “direct” fontmap implementation that would let you register fonts from files easily" work.I have try to start this work ,but it is slowly Can you give me some suggestions?Thank you very much!!!


Post a Comment

Popular posts from this blog

Building and using coverage-instrumented programs with Go

tl;dr We can create coverage-instrumented binaries, run them and aggregate the coverage data from running both the program and the unit tests.

In the Go world, unit testing is tightly integrated with the go tool chain. Write some unit tests, run go test and tell anyone that will listen that you really hope to never have to deal with a build system for the rest of your life.

Since Go 1.2 (Dec. 2013), go test has supported test coverage analysis: with the ‑cover option it will tell you how much of the code is being exercised by the unit tests.

So far, so good.

I've been wanting to do something slightly different for some time though. Imagine you have a command line tool. I'd like to be able to run that tool with different options and inputs, check that everything is OK (using something like bats) and gather coverage data from those runs. Even better, wouldn't be neat to merge the coverage from the unit tests with the one from those program runs and have an aggregated view of …

Testing for pending migrations in Django

DB migration support has been added in Django 1.7+, superseding South. More specifically, it's possible to automatically generate migrations steps when one or more changes in the application models are detected. Definitely a nice feature!

I've written a small generic unit-test that one should be able to drop into the tests directory of any Django project and that checks there's no pending migrations, ie. if the models are correctly in sync with the migrations declared in the application. Handy to check nobody has forgotten to git add the migration file or that an innocent looking change in doesn't need a migration step generated. Enjoy!

See the code on djangosnippets or as a github gist!

Augmenting mailing-lists with Patchwork - Another try

The mailing-list problem
Many software projects use mailing-lists, which usually means mailman, not only for discussions around that project, but also for code contributions. A lot of open source projects work that way, including the one I interact with the most, the Linux kernel. A contributor sends patches to a mailing list, these days using git send-email, and waits for feedback or for his/her patches to be picked up for inclusion if fortunate enough.

Problem is, mailing-lists are awful for code contribution.

A few of the issues at hand:
Dealing with patches and emails can be daunting for new contributors,There's no feedback that someone will look into the patch at some point,There's no tracking of which patch has been processed (eg. included into the tree). A shocking number of patches are just dropped as a direct consequence,There's no way to add metadata to a submission. For instance, we can't assign a reviewer from a pool of people working on the project. As a re…