📜 ⬆️ ⬇️

The dot42 project moves to a new format (C # 2 Java)

Dot42 project


image
The main goal of the dot42 project is to create Android applications using the C # language, without having to install the Mono interpreter using Microsoft Visual Studio or SharpDevelop. The project has aroused strong interest from mobile software developers since the publication of the technical preview in January 2013. Unfortunately, due to the complexity of the subject area, since January 2014, community activity has begun to decline significantly.


The main function and at the same time the fundamental problem of the project is the conversion of compiled C # code (IL code) into Java byte-code, which is executed in the Android system on the Davlik or ART virtual machine. Development and support of such a project requires deep and highly specialized knowledge in both formats of compiled byte-code and confident knowledge in the field of creation and support of compilers and cross-compilers. The number of specialists in this area is currently small.

DEX conversion

There are many shortcomings in transcoding IL-code to Dex, which are gradually eliminated during the development of the dot42 project. A decision has now been made to extend the .Net SDK with the addition of Java. The dot42 team attracted a PhD specialist in cross-compilation and software conversion to analyze the current state of the project. Its first task is to decide how to convert C # code to Java code.
')
Basically, there are two approaches:

image

Converting bytecode vs. Converting source code


Debugging problem

An error in converting bytecode from IL to Dex often causes the Java Virtual Machine to throw an exception "java.lang.VerifyError" . This exception is thrown when the Java interpreter notices that an attempt is made to load a class that has not previously passed the validation phase. Finding errors in this code is like trying to determine what was spoiled in the dinner box, while picking at the restroom of the restaurant. A typical example in this case is that the DEX code is successfully executed in the Davlik virtual machine, but falls inside the ART.
Converting source codes does not have this drawback; the Java compiler takes care of the correct location of the application bytecode.

Implementation experiments

Imagine that the dot42 team needs to add new functionality to the project, for example, to support async / await from C #. Work on PoC in bytecodes in this case is much more difficult and costly than similar improvements when converting source codes from C # to Java.

Compiler usage

Compilers for different virtual machines and architectural CPUs use different code optimization mechanisms. IL code generated by a C # compiler uses a stack architecture. On the other hand, the Davlik and ART virtual machines use the register model. The compiled C # compiler IL-code no longer contains information that would be useful for the Java compiler. On the contrary, when converting source codes, we allow the Java compiler to generate more efficient byte code.

Roslyn

Now, when Microsoft provides the open source Roslyn C # compiler, which contains a rich API for analyzing code, the dot42 command has a powerful tool that allows you to convert source code from C # to Java.

Transparent design

Ultimately, for developers using dot42, converting source code from C # to Java will make the process more transparent and supported. This process will allow you to open ready-made Java code in the popular IDE Eclipse or Android Studio.

Further development of the project

The dot42 team plans to release compiler utilities under the GPLv2 license. It should be noted that the GPL license does not apply to software created using dot42. Thus, thanks to the project, developers will be able to create native Android applications using C #.
The library's execution code has already been uploaded to Git under the Apache License 2.0 license. Anyone can create a fork of the dot42 project and extend the approach to converting IL-code to DEX.
Users no longer need to have a Professional license to create commercial applications using dot42. The next update is planned to remove the activation.

The dot42 command is going to replace the bytecode converter with a source converter. All utilities developed by the utility will also use the GPLv2 license, and the code for the execution of the library - Apache License 2.0.

Thank you so much for reading to the end!

Source: https://habr.com/ru/post/227705/


All Articles