Microsoft has open sourced JUniversal, a tool for writing cross-platform mobile applications in Java.
JUniversal is a transpiler, translating Java source code into C# source code while preserving code formatting and Javadoc comments. The tool is currently being enhanced to translate Java to Objective C++. The Microsoft Open Technologies group proposes this free tool for converting Android applications to make them run on Windows Phone and later on iOS.
JUniversal targets the business logic code of applications and not their user interfaces. The UI has to be written natively, separately for each platform.
There is one important limitation: not all Java libraries can be used. According to Bret Johnson, a Microsoft developer, “the Java -> C# source translator / transpiler itself only translates a few core Java classes, like String and StringBuilder. … For the the rest of the commonly used parts of the JDK, the expectation is that you use the JSimple libraries.” JSimple is a library containing support for:
- Basic language constructs:
AutoCloseable, Comparable, Iterable, Math
- File I/O:
Directory, File, Path, Reader, StringReader, Writer
, etc. - JSON
- Logging:
Logger, LoggerFactory
, etc. - Net:
HttpRequest, Socket, Url
, etc. - OAuth
- Unit Tests:
UnitTest, UnitTestBase
- Util:
Array, Collection, DateTime, HashMap, Iterator, List
, and others.
JSimple is extracted from Apache Harmony and has “a few enhancements thrown in” and “some rarely used functionality stripped out.” The idea is to “ensure that the code works consistently in Java and the target languages.” JSimple supports some of the latest features in Java such as lambdas.
The team behind JUniversal consider the tool stable enough for production use providing “you get it working for your needs.” Until the Java-Objective C++ transpiler works, they suggest using Google J2ObjC to translate Java code for the iOS platform. The developers are invited to make comments and suggestions on the project via its GitHub repository.