dot42 - C # compiler for Dalvik Runtime
The main drawback of Mono for Android is that applications require a separate runtime other than Dalvik. Although full access to the CLR looks very attractive, proxying and marshalling calls from one runtime to another can greatly affect performance. So why not remove the intermediate compilation into IL-code and get 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 cookies . And, although the project still does not reach the state of the combat product rival Mono, it is worth at least considering it and trying 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 to the new Register Language or, in short, RL. The main difference between IL and RL is that the IL code runs on the stack execution model (like Java bytecode ), and the RL code is registered , 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 post on the developers blog.
At each stage of the compiler’s work, the original debug information is saved, of course, the compiler has to convert it from the PDB format to the debag format for dex code. dot42 uses adb (Android Debug Bridge) to connect the debugger in Visual Studio.
After compilation, the Android libraries are used directly. The compiler understands most types, for example, java.lang.Boolean maps to System.Nullable <bool>. However, some gestures with data types still have to be done. Since dot42 operates directly with dex code, there are several restrictions on the functions and features of C # and .NET. Perhaps the most important of them is the lack of custom value types (structures). In the Dalvik virtual machine, there is simply no support for these types, therefore, it will not work to match structures.
A common question when using dot42: which 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 subtle add-on for ArrayList <E>, this is still additional code that will need to be included in the assembly and executed in the future.
dot42 -a commercial product (the professional version costs $ 399), however, there is a Community License that allows not only testing the product, but also publishing ready-made applications on Google.Play and similar stores. True, applications published in this way should be free.
To get started, you must register . The project has documentation , which is quite enough for acquaintance.
After installation, you can play around with examples from Samples.zip in the dot42 root directory. There is also a Hello World Tutorial .
I couldn’t connect my HTC One X (with Jelly Bean firmware) to Device Center , so I created a new emulator with the same software features: I
created a project, just like in Hello World Tutorial . I started it in a virtual machine and it really worked:
Unfortunately, the declared debugging support is still lame. Visual Studio 2012 after any fraud with debug just crashes and offers to restart itself. I have no opportunity to try for 2010. In any case, I think this is a temporary phenomenon.
By the way, on a real device everything looks about the same:
In general, I personally will be following the project with interest. : o)
If you see any errors, please report them in pm.
UPD.
Judging by the message on Twitter, the habraeffect was. :-)
In January, after 1 year of development, the authors of the dot42 project finally moved from promises to gingerbread cookies . And, although the project still does not reach the state of the combat product rival Mono, it is worth at least considering it and trying 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 to the new Register Language or, in short, RL. The main difference between IL and RL is that the IL code runs on the stack execution model (like Java bytecode ), and the RL code is registered , 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 post on the developers blog.
At each stage of the compiler’s work, the original debug information is saved, of course, the compiler has to convert it from the PDB format to the debag format for dex code. dot42 uses adb (Android Debug Bridge) to connect the debugger in Visual Studio.
After compilation, the Android libraries are used directly. The compiler understands most types, for example, java.lang.Boolean maps to System.Nullable <bool>. However, some gestures with data types still have to be done. Since dot42 operates directly with dex code, there are several restrictions on the functions and features of C # and .NET. Perhaps the most important of them is the lack of custom value types (structures). In the Dalvik virtual machine, there is simply no support for these types, therefore, it will not work to match structures.
A common question when using dot42: which 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 subtle add-on for ArrayList <E>, this is still additional code that will need to be included in the assembly and executed in the future.
dot42 -a commercial product (the professional version costs $ 399), however, there is a Community License that allows not only testing the product, but also publishing ready-made applications on Google.Play and similar stores. True, applications published in this way should be free.
Will we try?
To get started, you must register . The project has documentation , which is quite enough for acquaintance.
After installation, you can play around with examples from Samples.zip in the dot42 root directory. There is also a Hello World Tutorial .
I couldn’t connect my HTC One X (with Jelly Bean firmware) to Device Center , so I created a new emulator with the same software features: I
created a project, just like in Hello World Tutorial . I started it in a virtual machine and it really worked:
Unfortunately, the declared debugging support is still lame. Visual Studio 2012 after any fraud with debug just crashes and offers to restart itself. I have no opportunity to try for 2010. In any case, I think this is a temporary phenomenon.
By the way, on a real device everything looks about the same:
In general, I personally will be following the project with interest. : o)
If you see any errors, please report them in pm.
UPD.
Judging by the message on Twitter, the habraeffect was. :-)
@ dot42news For our Russian followers: http://habrahabr.ru/post/168689/