BT

Your opinion matters! Please fill in the InfoQ Survey!

Introducing dot42, a C# Compiler for Android’s Dalvik Runtime

| by Jonathan Allen Follow 247 Followers on Feb 06, 2013. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

The biggest downside of Mono for Android is that you are building on Mono, a completely separate runtime that what Android expects. And while there are certainly some advantages to having access to a full CLR, marshalling calls between it and Android’s Dalvik runtime can be expensive. So why not skip the IL code and emit Dex code directly?

Actually that is a slight exaggeration. The dot42 compiler doesn’t actually skip the IL. Rather, it reads the IL code and converts it into a new language called RL or Register Language. The main difference between IL and RL is that IL is stack-based (somewhat like Java’s byte code) while RL is register based. Once converted into RL, a set of optimizations are performed and the final product is compiled again. This last compilation gives us dex code, the language of Android’s Dalvik Runtime.

Through each step of the process the original .NET debugging information is maintained, though of course it must be converted from the Windows/.NET PDB format to dex’s debug information format. dot42 uses the Android Debug Bridge to connect the Visual Studio debugging facilities

Android Libraries are accessed by directly referencing JAR files. “After compilation, your calls are redirected to calls into the original Android libraries.” Some mapping between types is needed, but that is largely addressed by the compiler. For example, java.lang.Boolean is mapped to C#’s Nullable<bool>.

Because dot42 emits dex code, there are some C# features that you will not be able to use. The most notable of these is user defined value types, a.k.a. structs. Since they don’t exist in Dalvik, there is simply no way to map them.

When using dot42, you’ll often need to decide between the C# and Android versions of common data structures. For example, should you use .NET’s List<T> or Java’s ArrayList<T>? According to Ewout Prangsma, developers should favor the Java version if they are concerned about memory and download size. Even though their implementation of List<T> is basically a thin wrapper around ArrayList<T>, it is still extra code that needs to be packaged and shipped to the phone.

dot42 is a commercial product that starts at 499 Euro per developer with the usual bulk licensing options.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT