Vaadin and Android

We are working on an innovative platform called ‘Darwino’. One of the value proposition is to run mobile apps ‘offline’, meaning that both the data and the business logic can be executed locally, with the result replicated when the connection is made available. These mobile apps can be native or hybrid. For the later, we offer a local light web app server running on the mobile device and serving the business logic written in Java.
Going further, we’d like to integrate Vaadin and, in particular, we want to run it on the mobile device, in the local servlet container. If this seems easy first hand, we are encountering some issues due to the limitation of the Dalvik VM. The first one is a java.lang.VerifyError when loading com/vaadin/util/ReflectTools. It does not say much, but I bet this is because this classes use methods that are not available in the Dalvik VM. We have not investigated further yet.
Do you have any advise on how we can move forward? Is there a version of Vaadin that would compile, and execute, against the Android SDK instead of a JRE? Would be interesting to see, for example, what have to be done to the runtime to work on i-jetty (https://play.google.com/store/apps/details?id=org.mortbay.ijetty&hl=en).

Hi,

Sounds like an interesting project. I have never tried this and I’m not sure how much effort it would need to make Vaadin compatible with Dalvik, but I think this should at least be investigated. If you have experience on this field, I’d suggest to checkout the Vaadin codebase (
https://github.com/vaadin/vaadin
) and try working around these issue. It would be awesome if the codebase could be the same for Dalvik and std. JVM, but I guess a dalvik fork might be quite easy to maintain as well.

I’ll ping our engineers as well, if they could help you on this journey.

cheers,
matti

Hi.

I have no particular experience with Dalvik, but I might be able to help you with what I know about the internals of Vaadin Framework.

The error you’re seeing with ReflectTools is most likely caused by its use of API from the java.beans package that seems to be missing from Dalvik according to
https://code.google.com/p/android/issues/detail?id=51642
. Classes from java.beans are also used in some other parts of the framework, so you might want to look into either getting an implementation of that API to use in your project or alternatively check out the sources for Vaadin Framework and change them to use regular reflection instead. The java.beans usage in the framework is mostly a conveniance – I don’t think we depend on anything particularly complicated from that API.

I just saw a screenshot of a prototype from one of our experts who had just replaced java.beans package usage with “openbeans” project that replicates the same feature for Dalvik. Ilia will hopefully comment on this experiment soon. Interesting to see how well it will work!

That’s sound promising! I’m busy this week on customer projects but I will give it a shot as soon as can. It is clearly an issue with Java beans. I saw a few people hitting tihs issue already, and providing solutions (ex: https://openflow.stanford.edu/display/Beacon/Beacon+on+Android). Now, I have not experimented with it yet, and I wonder how it works as the deployment java.* package should be prevented.
Using openbeans is another solution, but this requires changes in the Vaadin code, as the package names are different. And this where I’m leaving my confort zone with Vaadin: eventhough I use Java since since its early days, I’m just brand new to Vaadin… So any help to get this started is greatly appreciated!

Matti has already disclosed my secret prototype. :slight_smile:
As Leif mentioned earlier, the problem is java.beans package.

Now I’ve made an experimental Vaadin branch with openbeans insead of java.beans

Vaadin sources are here:


https://github.com/elmot/vaadin-experimental-dalvik



https://dev.vaadin.com/review/gitweb?p=vaadin.git;a=tree;h=refs/heads/feature/dalvik;hb=refs/heads/feature/dalvik

Building Vaadin is a bit tricky and time-consuming, and I uploaded ready-to-use binaries here:

https://github.com/elmot/vaadin-experimental-dalvik

Prototype application (Vaadin-dalvik + jetty + one button) is here:

https://github.com/elmot/vaadin-experimental-dalvik-demo

Assembled .apk is here:

https://github.com/elmot/vaadin-experimental-dalvik-demo/tree/master/out

Hopefully those will help you.

IIlia, thank you very much. You work has been very valuable, and I’ve been able to run my first Vaadin ‘helloworld’ app on Android today, on top of Darwino.
Next steps are:

  • Work on a more elaborated application
  • Get the same code to work on iOS using RoboVM
    I’ll let you guys know how it goes.

For my Android app, I’m still using Eclipse and ADT. Then I got DEX errors because some files are duplicated across the jar files (css/, img/, license/, license.html, releasenotes.html). I had to strip them out manually from all the files, except vaddin-shared. Moreover, yuicompressor on maven central is including a copy of Rhino but also referencing a Rhino lib, leading to the same duplication problem. I don’t know how your Ant build deals with that.

Are you going beyond this POC for Android and officially target the platform? Would be great, for example, to have the recent builds available on maven central.

Anyway, thanks again for your help!

Hi Philippe,

Yes, please keep us informed how it goes.

I haven’t used Eclipse with ADT, and I build the project in Android Studio. I have no idea how it works but it builds the project without any problem. BTW my Ant build also fails because of the duplicates.

Most likely, you can throw away a yuicompressor at all. It’s required only for on-the-fly theme compilation, and I don’t think you really need that for your “embedded” server.

About future plans - now I am going to put this experimental build to our regular source tree as a “feature branch” and to our snapshot repository.
I’m affraid, we have no particular plans for Android support right now, and probably we can’t integrate those changes into a master branch of Vaadin 7 because of compatibility issues.

Good luck with Darwino!

Hello Ilia,
I’m currently stuck with the iOS version using RoboVM, as I’m getting the following exception:
INFO: Requested resource
[/VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/undefined.cache.js] not found from filesystem or through class loader.
The same Vaadin code works with Android and J2EE. On these platforms, the URL is:
VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/00B793CDF5E1D54D501EE2358045A003.cache.js
So I’m wondering how the 00B7…003 name is resolved and why it comes ‘undefined’ with iOS. I verified that the client-compiled.jar resources are properly included, and they are.
Any hint?

Actually I fixed the issue. It was coming from the USER_AGENT that was not properly set on iOS. Fixing this made it work! So I have a Vaadin app running offline on an iOS device.

Cool! Is it possible to share your prototypes in e.g. github? I’d love to try the setup myself as well and it’d help other community members playing with similar stuff.

Yes we will. We are in the process of creating a new organization, darwino.org, that will support these projects. This should come in the next few weeks.

What was recently done:

Thanks you very much - we are actually starting a project involving Vaddin and we’ll let you know

The demo app does not work on my Sony M4. I need to resolve that.

Strange effect. After several days it started working. No idea why.

Hi Ilia,

i just started to use the dalvik 7.7 prerelease building an android hosted web frontend for a project. Would it be possible to build 8.1 for dalvik?

thanks for your first releases!

Timo

Hey guys!

I stumbled upon this thread whilst doing a bit of research as we’re looking to do a similar thing, but for version 8…

Ilia, Philippe & Matti, I have a few questions for you guys, hope you can help out!

  1. What did you do in order to convert the vaadin jars to run on dalvik?
  2. Was it a simple ‘change to use openbeans’ or was it a bit more complicated where the classes & dependencies had to be converted to dex files, then recompiled into the jars?

I’ll probably look to build up a script to perform these tasks in future if I can successfully convert them, and I’m happy to share my findings and what was required to finalize these. Which should make it easier to maintain new vaadin versions.

Another thing I’m considering doing, is based off Ilia’s project above, I might look into modifying the android app itself to use a WebView and point to the localhost instance on the device (mocking a truely native look). Whilst seeing if there’s a way to listen to window posts from the android app in order to trigger other applications.

Looking forward to hearing your thoughts!

Cheers,
Mat