Xamarin, in an experiment, proves that .NET and C# could be used instead of Java for Android – to better effect performance-wise – enabling Google to sidestep patent issues.
Xamarin has ported Google’s Java-based Android software to use C# and the .NET framework.
In light of the ongoing legal battle over Java between Google and Oracle, 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, it’s 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 that “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 Microsoft’s legally binding community promise.”
Indeed, in a 2005 email Google’s Android chief Andy Rubin told Google co-founder Larry Page: “If Sun doesn’t 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 Android’s Dalvik is a young virtual machine and is not as tuned or performant as Xamarin’s 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 Android’s 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, “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,” de Icaza said.However, a de Icaza added that few technologies 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 Mono’s 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.