📜 ⬆️ ⬇️

Android port on C # - Miguel de Icaza

A serious $ 1 billion patent war broke out between Oracle and Google, for the right to use Java in Android.

But Java is not the only way to create applications, in fact, not even the best. As an alternative, we proposed C #, achieving high performance and low battery consumption. Our new platform is an open implementation of the .NET Framework, which allows developers to write C # code, adapt it to the Java system, and reuse part of the code for iOS and Windows Phone.


')
Unlike Sun with Java, Microsoft has sent C # and .NET VM for standardization in ECMA. The system is protected from patent claims by strict ISO requirements, as well as Microsoft's commitment .

Last July, when Xamarin began work, we put together a team in Boston to plan the development of Mono on iOS and Android. After a day of "kayaking" on the Charles River, at lunch, we thought about how to improve Mono for Android in order to improve the performance and battery life of applications.


The Xamarin team after a day of kayaking, then we were still a small company.

Time after time, we faced the same problem: Dalvik is not as productive as Mono and suffers from the limitations inherent in Java without Oracle's Hotspot optimization.

What if you replace Java with fast C # and get rid of the limitations of Dalvik? Is it possible to create an Android phone completely free from the disadvantages of Java and Dalvik VM?

At dinner, a crazy idea crept into my head: recompile Android source code under C #. Android will benefit from the structure of P / Invoke and real generics.

Although nothing was done in July, the idea did not leave us. A few months later, arguing over the improvement of Mono for Android, it was decided to rewrite all Android source code in C #. Thus was born the project XobotOS.

XobotOS


As a result, most Android layouts currently run on C #. Here is a screenshot of XobotOS running on a Linux workstation, without Java:



To achieve this, it was necessary to recompile most of the Java component of Android in C #. So how did we do it?

Java translation by Sharpen


We understood quickly recompiling code in C # is unreal. Android source code contains about a million lines of Java. In addition, I wanted to keep up with new releases of Google. The only way out was to automate the process.

Sharpen became the tool we used as a starting point. That's what Frank Kruege says about this. ( Port Java applet in app on iPad )

Having made changes in Sharpen, received the tremendous Java translator in C #. Now our team is releasing its version of Sharpen for XobotOS.

Starting from Android 2.x source code back in 2011, we managed to upgrade XobotOS to Android 4.0 Ice Cream Sandwich.

Performance


So, you run Mono on Android, a question that suggests itself - what is the difference between Mono and Dalvik?

When C # appeared, Microsoft did a lot to optimize it. Value types , virtual methods in the form of opt-in instead of opt-out were introduced. Later, Java and C # broke up in a way to implement generics . Java went through backward compatibility, while C # introduced support for generics in runtime. Retaining ease of use and installation, C # has proven to be a reliable tool.

Since then, the programming language and environment has continued to evolve. C # initially had all the prerequisites for superiority over Java many times. Starting from dynamic programming, to asynchronous language, iterators, functional programming, concurrency, and excellent implementation of generics. Many of these features are available through research conducted by Don Syme and his F # team.

Moreover, Mono as a virtual machine has been developed over the past 10 years and currently has 8 generations.

You can see a huge difference in the performance of structures and generics in this test , which we launched on a simple implementation of a binary tree in Java and C #:



What's next?


We are proud to announce that XobotOS is available on GitHub, so everyone can try it out for themselves.

Our goal was to create a better platform for developing mobile applications. XobotOS is an interesting experiment and, as it turned out, many of the technologies found will be useful for use in future products:

Direct Graphics Access on Skia: At the moment, Mono for Android is accessing low-level graphics libraries via Java. In XobotOS, we removed this intermediate layer and use Mono P / Invoke to get direct access to the render in Skia.

Java to C # tooling: All of our new Sharpen versions are available as part of XobotOS.

We have all the tools to replace part of Java code with C # where performance is important and where C # is the best solution.

It turned out that the experiment about which we thought: “It would be fun to realize!”, Gave serious advantages to Xamarin products. Of course, it is important to be focused on what you are doing, but sometimes, without trying something really crazy, it is impossible to succeed. Who knows, maybe Google will thank us one day ...;)

(Posted on May 1, 2012)

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


All Articles