This week in Discobot (45.2011)

Another night of coding, another update on the Discobot project! For those unfamiliar with the Discobot project: it’s the project name for running Groovy on Android. We (Marcin Erdmann and Erik Pragt) are working towards an easy to use framework to run the newest version of Groovy on the newest version of Android. Currently, we’re not there yet, but we will demonstrate our progress at the next Groovy and Grails Exchange in London.

A small update though on our current progress, since it has been a while since our last update, and we’ve gotten a few requests to update you all. To start with: the project is still very alive, and we are working hard to create a streamlined environment for developing Groovy Android applications, including Gradle support, with some tasks to easily deploy your Groovy application on the Android emulator.

The last couple of weeks we’ve been struggling to work with the dynamics provided by Groovy. Groovy works a bit different compared to the standard Java runtime in Android. A small example:

This code dynamically creates a class at runtime. We have to make the Android environment aware of these classes, which is done by the DiscobotClassloader. This is quite tricky to accomplish, but the good news is, that after some days and nights of coding, it works now. Basic Groovy code, like

was already working for quite some time, but now we support a great deal of the features provided by Groovy already at the moment. Even though we haven’t measured yet how far we are exactly in terms of features, but we’re on the right way.

What we’ll do now though, is to create an Android application which will run all Groovy unit tests. We’ve done it before, and around 30% of the unit tests worked on the Android emulator. Now, with the support for dynamically generating classes, which was one of the biggest problem, we should get far above this 30%. So, please bear with us and we’ll keep update you on the progress we’ll make.

This week in Discobot (40.2011)

After some hectic times at work caused by very tight deadlines and me getting married in the beginning of September we finally managed with Erik to get back to working on Discobot last week.

Some of you have probably already noticed that we have a talk on Discobot scheduled at Groovy & Grails Exchange 2011 in London which takes place in early December. Although the progress is good there is still quite a lot of work to be done on Discobot and we decided that probably one evening a week will not be enough. On the other hand knowing about the talk gives us an even stronger motivation to succeed!

Last week Erik continued his work on getting all Groovy tests running in the emulator. We found out that ‘on the fly generated’ classes which are created by Groovy when you for example cast a map of closure into a class using ‘as’ keyword cannot be loaded by the classloader. The reason is simple – classloader looks for class files but it should be looking for dex files. This is our main concern at the moment as it causes exceptions all over the place and breaks anything more complex than a ‘hello world’. From the code written by Hjalmar we’ve noticed that he also encountered the problem and we’re trying to apply his solution to see if it will work. So, it looks like there’s a lot of class loading fun ahead of us!

We’ve also got a response from guys behind Gradle plugin for Android about our pull request. They had several small remarks which I managed include in my second pull request. From what they said it looks like they should accept it in the coming days.

I’ve also looked for options regarding a repository in which to put our artefacts (Gradle plugin and the modyfied version of Groovy). I’ve found a nice blog about creating a a github based Maven repository and using it with Gradle. It seems easy and straightforward so probably we will go for this solution for now.

This (two) week(s) in Discobot (30-31.2011)

Each week, we work on the Discobot project, which goal it is to make Groovy run on Android. While that in itself isn’t the biggest problem, as you can read in our previous blog posts, making developing for Android using Groovy and making sure we are feature complete, well, let’s say it’s challenging.

Current efforts are twofold: one is developing a set of developer tools using Gradle, on which Marcin is focusing the most. On the other hand, we need some tools to make sure our version of Groovy works on Android, which is what I (Erik) am focusing on.


As you can see in the screenshot above, our project is already capable of building the project and installing it on the emulator using the Gradle plugin. Also, the start of a demo application has been built, which will allow us to run all the tests packed with Groovy. For that, we have tweaked the build process of Groovy itself, so that it produces a jar which includes all the tests. This jar is used in the Discobot project. To figure out which tests are available, an Android Classpath Scanner is used. It uses a hack by inspecting the Dex files itself, but we are currently using that to scan for files which extend from GroovyTestCase, and run those. Once that is working, we’ll probably write a better UI around it.

Also, the Gradle plugin still needs some finishing touches to improve the overall user experience. Marcin is currently working on the last gradle task which will initialize the android project structure. It will call the android create project command-line tool from Android SDK, change the src directory structure of your project to obey Gradle conventions and create a ‘Hello World’ activity written in Groovy, so you can quickly get a simple working application to start out with!

We’ll try to update you again with more information next week!

Live Blog: Groovy Android programming

This blogpost will keep track of our current progress on our effort to make Groovy run on Android phones. Instead of creating a summary like in the previous ‘This Week in Discobot’ posts, we will update this blogpost every half an hour!

Erik (20:36): after a nice dinner, we make a small plan for the evening. Marcin will work on committing and pushing the Gradle Android plugin into our Github fork, while my plan will be to continue to build a small Android application which will run the entire Groovy testset on Android, to assure our code works as we expect it to work.

Marcin (21:39): Erik created a small test program which successfully runs the Groovy unit testcases using the AllTestSuite. Next plan is to extend that so it also works on the Jar, so classpath scanning needs to be implemented.  I the meantime, I worked on the way that intermediate files are organized in the Gradle Android Plugin and I added a test to verify signing the APK with the Android debug key works.

Erik (22:14): Investigating Reflections to use as a classpath scanner in Groovy

Erik (23:19): One hour later, still little success with the classpath scanning. Some testfiles aroud found, some aren’t, and doing a ‘reflections.getSubTypesOf(GroovyTestCase.class)’ currently returns an empty list. Not what I expected.

Marcin (23:37): I’m done with all the changes I wanted to do on the Gradle Android plugin. Now I’m writing the first integration test for the Gradle Discobot plugin. As I’ve never done this before for a Gradle plugin I’m using integration tests from the Gradle Android plugin as an example on how to do it.

[nggallery id=3]

Erik (0:58): After hacking around with the reflections project with Marcin, it’s time to call it a night. We got the classpath scanning to work now, but with a little bit more troubles than expected. Wrote an email to the authors of Reflections to ask them if they can explain some of the choices they made.

Good night everyone, and thanks for reading!

This (two)week(s) in Discobot (27-28.2011)

We continued our work on getting Groovy working on Android over the past two weeks.

Erik has made quite a good progress with the tests suite for Discobot. What he has achieived by now now is a slightly modified original Groovy test suite running against the compiled but not packaged (jared) code of our patched version of Groovy on his laptop. And of course it’s all green! As we removed some unnecessary classes and had to patch other, because the Dalvik VM doesn’t provide all the classes that regular Java does, Erik also had to remove and change some of the tests but we are trying our best to keep the needed patching to a minimum. It all looks promising and the next step for Erik is to run the tests against a jar and then create an Android app that will run all the tests on the emulator/device. We need that to learn if the differences between Dalvik and regular Java will break any tests and we can do that only by running the tests on a real Dalvik VM. This will give us some confidence that when people start using Discobot for something more complex than a ‘Hello World’ app things won’t start to break big time.

One of the concerns when Hjalmar Ekengren started his first efforts to run Groovy on Android as his GSoC project was the performance. I recall him telling me that it took up to 20s to start even a really simple app back in 2009 in the emulator. Apparently the things have improved quite a lot and our simple ‘Hello world’ example loads in the emulator in less than 5 seconds. It’s still quite long in my opinion. But last week when I uploaded our test application to my HTC Desire running Android 2.2 I was really surprised how quick it loaded the app – I think it’s less than a second! So we don’t have to worry about the performance, at least at this stage of the project.

For the past two weeks I worked hard on modifying the Android Gradle plugin and creating the Discobot Gradle plugin. Thanks to the extensive documentation that the Gradle project has and a terrific example in the original Android Gradle plugin it wasn’t hard to understand Gradle concepts. And when you get the main principles of Gradle it’s a real pleasure to work on a Gradle plugin.

I’m basically done with all the changes that had to be made to the Android Gradle plugin so that the Discobot Gradle plugin could extend it and use it for its own needs. The last thing I need to work on is the documentation – the changes I’ve made are breaking for the Android Gradle plugin and I think that if I update the docs the developers of that plugin will be happier to accept my pull request. I tried to contact the github repository owner of the Android Gradle plugin (Jason Voegele) before I started the work on it to learn what is his view on the changes I planned to make but unfortunatelly I didn’t get a response to my email. Hopefully when I create the pull request someone will get it processed…

Also the Discobot Gradle plugin is almost ready. Currently it builds the Android projects that use Groovy without a problem. I still want to add one task to it that will create the project structure and default files (AndroidManifest.xml and the main activity class among others) so that it will be easier to start the project from complete scratch with only a build.gradle file in your project. The task, updating Gradle Android plugin’s documentation and creating a pull request on my changes are my goals for the next week.

This week in Discobot (26.2011)

Currently, we (Erik Pragt and Marcin Erdmann) are working on getting Groovy to run on Android and make the process as smooth as possible for other developers. On this blog regular updates will be posted to inform you about the progress we made, the problems we ran into and how we solved them. This is the first episode of ‘This week in Discobot’. Read more