OpenJDK Mobile: An Outstanding Plan to Create iOS Apps by Java

Recently both OpenJDK and Java Community has suggested a plan to make java available on the iOS platform. The community said that they are planning to restart their work on the OpenJDK Mobile center project to achieve this goal. 

OpenJDK (Open Java Development Kit), a FOSS (Free and Open-Source Software) employment of Java SE (Java Platform Standard Edition) was created by OpenJDK and Java Community, IBM, SAP, Red Hat, SE and Apple Inc.

 Apart from that, it is mainly applied to create solutions suitable for OpenIndiana, Mac OS X and Linux and other platforms.

OpenJDK was introduced in 2007. It recently got an update under the name of “OpenJDK Mobile Center” and came into the limelight. 

The update has brought a new set of APIs to the Android and iOS. This helped the developers to use Java development tools on their mobile devices.

Moreover, it also includes some other features, like handling the UI control for the client control applications, controlling an uninterrupted communication by using the server-side cloud as well as third-party services, and applying platform-specific APIs to build a local executable for both Android and iOS devices. 

Main Focus of Java on iOS Platform

The main focus of the OpenJDK Mobile has always been on the iOS platform. This is because Android has always supported Java for development. However, that is not the case when it comes to iOS. Apple iOS has not supported any version of Java till date.

The team decided to introduce GraaLVM with the vision of making Java active on both the platforms. It was introduced for an efficient compilation of code in iOS. Undoubtedly, it will help the developers to compare their Java code with their local libraries and make the codes processable in iOS. 

Benefits of Java in the iOS Platform

The introduction of Java in iOS will prevent the developers from getting into the inconvenience of learning C or Swift to enter the development world of iOS.

 Besides, the developers will also get the cross-platform feature of the Java to create the iPhone solutions thereby, getting an advantage in this competitive market.

This is an indication of Java going for revolutionary development in the mobile application industry. Furthermore, it is a good opportunity for both Java developers as well as the application developers of iOS and Android. 

Implementation of OpenJDK Mobile on iOS Platform

The x64 in iOS utilizes the Hotspot JIT, whereas the ARM 64-bit’s usage is limited to the Zero interpreter. JDK 9 in iOS supports both of these device execution tools. 

This limitation of the ARM does not allow the active usage of the Hotspot. To overcome this drawback, we have to depend on the Zero “C” interpreter of the iOS device.  

Requirements For Building

Here, I am going to discuss about 4 Requirements for Building.

1. Machine

The JDK 9 of iOS needs a Mac System eligible to process an Xcode 7+. Xcode 7, needs a minimum requirement of OSX 10.10.5 (Yosemite) for a smooth run.

2. Xcode

This project needs an Xcode 7.1, that is available to download at the developer’s site for Apple.

3. libffi (required by ARMs only)

The iOS ARM 64 having the Zero interpreter, needs a third-party library for the local functions. This library is known as libffi. At present we are using the version 3.2.1 of the library.

  • You have to download libffi 3.2.1.
  • After downloading the bundle, you have to unpack it at a working directory, “cd” within the directory.

Then follow the given commands:

% xcodebuild -arch arm64

% cd build_iphoneos-arm64

% make prefix=`pwd` install

By clicking the “make install”, you can make the library, crowd, the lib and directories in the build_iphones-arm64 with the libffi library to create the JDK.

4. Libfreetype

To create an iOS x86_64 distribution, you have to first download the sources, cd in the top directory and then run the following commands:

./configure \

–without-zlib \

–without-png \

–without-bzip2 \

–host=x86_64-apple-darwin \

–prefix=`pwd`/build_iphoneos-x86_64 \

CFLAGS=’-arch x86_64 -miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/’ \

LDFLAGS=’-miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/ -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system’

make clean

make

make install

The result of the build will get stored in the build_iphoneos-x86_64 directory. 

To create an iOSarm64 distribution, run the following commands:

% ./configure \

–without-zlib \

–without-png \

–without-bzip2 \

–prefix=`pwd`/build_iphoneos-arm64 \

–host=arm-apple-darwin \

–enable-static=yes \

–enable-shared=no \

“CFLAGS=-arch arm64 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=8.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/’ \

AR=/usr/bin/ar \

‘LDFLAGS=-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ -miphoneos-version-min=8.0’

% make clean

% make

% make install

The result will get saved in the built_iphoneos-drm64 directory.

Requirements to Create the JDK

After building the required tools and libraries, download the mobile/dev sources. Following that, make sure to modify the build command mentioned below so that you can match the system setup and run the build script.

Build Command for x86_64

# !/bin/csh

#

# Customize the following paths to match your setup

#

setenv CUPS_DIR $HOME/jdk9mobile/cups/include

setenv FREETYPE_DIR $HOME/jdk9mobile/freetype-2.6.2/build_iphoneos-x86_64

setenv JDK_DIR /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

#

cd mobile-dev

bash configure \

–enable-option-checking=fatal \

–build=x86_64-apple-darwin \

–host=x86_64-macos-ios \

–target=x86_64-macos-ios \

–disable-warnings-as-errors \

–enable-headless-only \

–with-boot-jdk=$JDK_DIR \

–with-jdk-variant=normal \

–with-jvm-variants=minimal1 \

–enable-static-build=yes \

–with-extra-cflags=”-arch x86_64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0″ \

–with-extra-cxxflags=”-arch x86_64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0″ \

–with-extra-ldflags=”-arch x86_64 -miphoneos-version-min=8.0.0 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system” \

–with-cups-include=$CUPS_DIR \

–with-sys-root=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \

–with-tools-dir=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/../../usr/bin \

–with-debug-level=release \

–disable-precompiled-headers \

–with-freetype-lib=$FREETYPE_DIR/lib \

–with-freetype-include=$FREETYPE_DIR/include/freetype2

cd build/ios-x86_64-normal-minimal1-release

make images

Command to Build Arm64 

# !/bin/csh

#

# Customize the following paths to match your setup

#

setenv LIBFFI_DIR $HOME/jdk9mobile/libffi-3.2.1/build_iphoneos-arm64

setenv CUPS_DIR $HOME/jdk9mobile/cups/include

setenv FREETYPE_DIR $HOME/jdk9mobile/freetype-2.6.2/build_iphoneos-arm64

setenv JDK_DIR /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

#

cd mobile-dev

bash configure \

–enable-option-checking=fatal \

–build=x86_64-apple-darwin \

–host=aarch64-macos-ios \

–target=aarch64-macos-ios \

–disable-warnings-as-errors \

–enable-headless-only \

–with-boot-jdk=$JDK_DIR \

–with-jdk-variant=normal \

–with-jvm-variants=zero \

–enable-static-build=yes \

–with-libffi-include=$LIBFFI_DIR/include \

–with-libffi-lib=$LIBFFI_DIR/lib \

–with-extra-cflags=”-arch arm64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0″ \

–with-extra-cxxflags=”-arch arm64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0″ \

–with-extra-ldflags=”-arch arm64 -miphoneos-version-min=8.0.0 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/system” \

–with-cups-include=$CUPS_DIR \

–with-sys-root=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \

–with-tools-dir=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin \

–with-debug-level=release \

–disable-precompiled-headers \

–with-freetype-lib=$FREETYPE_DIR/lib \

–with-freetype-include=$FREETYPE_DIR/include/freetype2

cd build/ios-aarch64-normal-zero-release

make images

After completing these steps, you have to open the hello-ios-x86_64/hello.xcodeproj in the Xcode program. 

In Xcode, you have to select Build and Run.

After completing the process, the simulator will appear using the Hello application. Thus, you have to click on Run Java Button. The Java will be initiated by displaying the Hello World in the Xcode console.

Conclusion 

I hope that this article helped you to know more about OpenJDK Mobile. There is no doubt that this new JDK will help the developers to a greater extent. Hopefully, developers will be able to use Java on iOS to create applications without any issue. 

Leave a Reply

Your email address will not be published. Required fields are marked *