Xamarin has ported Googles Java-based Android software to use C# and the .NET framework.
In light of the ongoing legal battle between Google and Oracle over Java, this development proves that there are options for Google if Oracle triumphs.
The research project, called XobotOS, ported Android 4.0 from Java/Dalvik to C# to explore the possibilities of improving the performance and memory footprint benefits that C# brings in by leveraging the best parts of .NET/C#, such as real generics, P/Invoke, structures, etc. And they have opened the source code for it under Apache 2.0 License.
Xamarin CTO Miguel de Icaza, in a blog post about the project, said:
Java is not the only way to build native apps on Android. In fact, its not even the best way: we have been offering C# to Android developers as a high-performance, low-battery-consuming alternative to Java. Our platform, Mono, is an open-source implementation of the .NET framework that allows developers to write their code using C# while running on top of the Java-powered operating system, and then share that same code with iOS and Windows Phone.
Indeed, de Icaza added, Unlike Sun with Java, Microsoft submitted C# and the .NET VM for standardization to ECMA and saw those standards graduated all the way to ISO strong patent commitments. The .NET framework is also covered by Microsofts legally binding community promise.
Indeed, in a 2005 email, Andy Rubin, Googles Android chief told the company’s co-founder Larry Page: If Sun doesnt want to work with us, we have two options: 1) Abandon our work and adopt MSFT CLR [Common Language Runtime] VM and C# language; or 2) Do Java anyway and defend our decision, perhaps making enemies along the way.
De Icaza said Androids Dalvik is a young virtual machine and is not as tuned or performant as Xamarins Mono. So the Xamarin team set out to swap Java with C# and avoid the Dalvik limitations. Thus far, the result is that the team has most of Androids layouts and controls entirely in C#, de Icaza said.
The team started with a Java translation tool called Sharpen from db4o, which is an open-source Java to C# converter. In the process, the Xamarin team matured the Sharpen tool to improve its Java-to-C# translation capabilities, and on May 1 released a new version of Sharpen along with the code for XobotOS. XobotOS is available on Github.
As a result of their efforts, Mono now blows Dalvik away in benchmark tests, de Icaza said. However, he said, Our goal as a company is to provide the best platform for building mobile apps, and so XobotOS will not be a focus for us going forward.
However, de Icaza in his blog post pointed to a few technologies that have come out of the effort that Xamarin will be able to include in future versions of its products:
- Direct graphics access to Skia: Currently Mono for Android accesses the underlying graphics libraries through Java; with the code that we built for XobotOS, we will skip the middleman and use Monos P/Invoke to get straight to the native rendering code in Skia.
- Java to C# tooling: Our new version of Sharpen is available as part of the XobotOS release.
- Replacing Java code with C# code: We now have the tools necessary to replace some chunks of Java code with C# code where performance is critical and when C# can offer better solutions than Java has. Our plan is to take elements of the research project and integrate those into our products.