The main disadvantage of Mono for Android is that applications require a separate runtime environment, different from Dalvik. And while full access to the CLR looks very attractive, proxying and marshalling calls from one runtime environment to another can greatly affect performance. So why not remove the intermediate compilation in the IL code and get a working Dex code right away? This is
what the dot42 project
does .

In January, after 1 year of development, the
authors of the dot42 project
finally moved from promises to gingerbread . And, although the project still does not reach the state of Mono's competitive product, it is worth at least consider and try it.
I admit, I was a little cunning, saying that the dot42 compiler "removes" the IL-code. This is not entirely true. Instead, it reads the IL code and converts it into the new Register Language language or, if it is shorter, RL. The main difference between IL and RL is that the IL code works on the
stack execution model (like the
byte code of Java ), and the RL code on the
register one , just like Dalvik. After receiving the RL code, dot42 performs a number of optimizations and the final compilation stage begins. It is after the last stage that the dex-code, the language of the Dalvik environment, is obtained. What is the difference between RL and Dex is written in the
very first blog post of developers.
')
At each stage of the compiler's work, the original debag information is saved, of course, the compiler has to convert it from the PDB format to the debag format for the dex code. dot42 uses adb (Android Debug Bridge) to connect a debugger in Visual Studio.
After compiling, Android’s libraries are used directly. The compiler understands most types, for example, java.lang.Boolean is mapped to System.Nullable <bool>. True, some gestures with data types still
have to be done . Since dot42 operates directly with dex code, there are several limitations on the features and capabilities of C # and. NET. Perhaps the most important of them is the absence of custom value-types (structures). In the Dalvik virtual machine, there is simply no support for these types, so it’s impossible to match the structures.
A common question when using dot42 is: what data structures to use, .NET or Android? For example, what to use, System.Collections.Generic.List <T> or java.util.ArrayList <E>? One of the dot42 developers, Ewout Prangsma,
advises giving preference to Java classes. Even though List <T> is a thin add-on above ArrayList <E>, this is still additional code that will need to be included in the assembly and run later.
dot42 is a
commercial product (a professional version costs $ 399), however, there is a Community License that allows you not only to test the product, but also to publish ready-made applications in Google.Play and similar stores. True, applications published in this way should be free.
Let's try?
To start work you need to
register . The project has
documentation , which is enough for dating.
After installation, you can play around with examples from Samples.zip in the dot42 root directory. There is also the
Hello World Tutorial .
I could not connect my HTC One X (with Jelly Bean firmware) to the
Device Center , so I created a new emulator, with the same software features:

Created a project, all in
Hello World Tutorial . I started it in a virtual machine and everything really worked:


Unfortunately, the claimed debugging support is still lame. Visual Studio 2012 after any frauds with debug just drops and offers to restart itself. Try for 2010 I do not have the opportunity. In any case, I think this is a temporary phenomenon.
By the way, on a real device everything looks approximately the same:

In general, I personally will follow the project with interest. : o)
If you see any errors, please report them to PM.UPD.
Judging by the message on Twitter, habraeffekt was. :-)
@ dot42news For our Russian followers: http://habrahabr.ru/post/168689/