Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
Delphi

Adopting the OpenJDK for Delphi Android Development

Adopting the OpenJDK

 

In this post, you’ll learn how to install OpenJDK, which is required for using the Windows IDE for Android development. Continue reading to learn why you should use the OpenJDK and how it can help your development journey.

You might not realize it, but Java comes in a variety of flavors and parts. Oracle became the official owner of the Java trademark and the main “official” Java distribution after acquiring Sun Microsystems.

First off a disclaimer: I’m not a lawyer, nor am I a Java developer. This is a high-level overview of a number of complex issues related to Java, Java development, and licensing. My goal is to give you enough information to move forward and be successful, but I encourage you to do some additional research and consult a lawyer if you need additional information. I know that I will miss details and gloss over important points.

Java is made up of the following parts

  • JVM: The Java Virtual Machine is the virtual machine that runs all Java applets. Java applets are usually distributed as Java bytecode in a JAR file. Java bytecode doesn’t run natively on the physical computer. Instead, it runs on the JVM. The JVM is a Just-in-Time compiler (JIT) that converts the Java bytecode into native machine code.
    • The two popular flavors of the JVM are Hotspot (the official JVM used by the Oracle JDK) and OpenJ9.
    • Technically Android doesn’t have a JVM. Instead, the Java bytecode is converted into Dalvik bytecode and run on the DVM (Dalvik Virtual Machine) or compiled by ART (Android Runtime). Both use .dex files, but ART translates the bytecode into .elf (Executable and Linkable Format) files. This article is mostly focused on the Java desktop side for building Android apps with Delphi, but I wanted to add this aside for clarity.
  • JRE: The Java Runtime Environment contains the main libraries a Java applet needs to run, along with the JVM. It includes Java.exe and Javaw.exe that run the applets and other utilities.
  • JDK: The Java Development Kit, or the SDK for Java development. The JDK is a superset of the JRE. This is what you use for building Java (and Android) applications, while it also provides everything you need to run Java applets. It includes a number of utilities like KeyTool.exe and JarSigner.exe used to make
  • There are 3 variants of the Java platform released by Oracle: Standard Edition (Java SE), Enterprise Edition (Java EE), and Micro Edition (Java ME). This blog post, and most use cases you will encounter, involve the Standard Edition.

Where it gets interesting is with the OpenJDK, a free and open-source implementation of the Java Standard Edition (SE) Platform. It is the official reference implementation of Java SE since version 7. The source implementation is licensed under the GNU General Public License version 2 with a linking exception. [wikipedia] Similar to how Chrome is based on the open-source Chromium project, Java SE is based on OpenJDK.

Anyone, yourself included, could download the OpenJDK source files and create a binary build. There are a number of organizations that do that, and each one has its own spin on licensing, support, and included components. Here are a few (these are binary distributions of the OpenJDK source).


Build
Long Term
Support
Permissive
License

Pure
Commercial
Support
AdoptOpenJDK /
JClarity / IBM Java SDK
Yes Yes Optional Yes
Alibaba Dragonwell Yes Yes No Yes
Amazon Corretto Yes Yes No No
Azul Zulu Yes Yes No Yes
BellSoft Liberica JDK Yes Yes No Yes
ojdkbuild Yes Yes Yes No
Oracle Java SE Yes No No Yes
Oracle OpenJDK No Yes Yes No
Red Hat OpenJDK

Yes

Yes Yes No
Red Hat for Windows Yes Yes No Yes
SAP SapMachine Yes Yes No No

Source: https://en.wikipedia.org/wiki/OpenJDK 

Oracle provides direct OpenJDK builds, but those builds directly from Oracle do not include long term support or commercial support. For that Oracle wants you to switch to Oracle SE, which does not have a permissive license (Oracle recently changed the licensing on their Standard Edition JDK to charge an annual fee for commercial use). So while OpenJDK source has a permissive license, the binary distribution from Oracle does not have the same license.

That is where AdoptOpenJDK (and others) come in. They take the open-source OpenJDK source files and provide a binary distribution with long term support (updates and fixes for old version), a permissive license, and commercial support. AdoptOpenJDK is maintained and backed by the community and a number of large companies including IBM, GoDaddy, Microsoft, and Red Hat.

RAD Studio doesn’t directly depend on Java, but if you are using the Android SDK to target Android then you are using it. The current RAD Studio installer offers you the option to install the standard Oracle JDK if you don’t already have one installed. In the future (approximately 10.4.x timeframe), Embarcadero is planning to change the default option to install AdoptOpenJDK.

The decision for which JDK and JRE to use is up to you. In this blog post, I will walk you through switching to the AdoptOpenJDK with HotSpot JRE (HotSpot is the official JVM used by the Oracle JDK, but there are others you can choose from.)

Before You Begin

If you already have Oracle’s JRE or JDK installed, you may want to uninstall it. Unless you have other software on your computer that depends on it specifically. If you only installed it for Android development with Delphi then you are fine to uninstall it. Because of the way it updates you may discover you have multiple versions installed.

Installation

Visit https://adoptopenjdk.net/ and if you are on a Windows computer it should default to the download you want. Yes, we want version 8 even though there are new versions. Version 8 is the most popular version for most use cases, including for Android development, and the different versions are not compatible.

Downloading AdoptOpenJDK

If you are on a 32-bit version of Windows, you really need to upgrade to a 64-bit platform. Go do that and come back when you are done. You do not need to install the 32-bit version on 64-bit Windows. If you happen to be visiting the website from a different computer though, you can go to the other platforms/releases page and find the download you need there. You need the full JDK (which includes the JRE), not just the JRE, for Windows x64.

Downloading AdoptOpenJDK for Windows x64

During the installation, you will accept the GNU GENERAL PUBLIC LICENSE. This is only for the JDK and does not impact any projects you develop (again talk to a lawyer or read the licenses yourself to be sure.) I like to have the installer set the JAVA_HOME environment variable, but that is optional. Otherwise, you can go with the defaults.

Customize Your AdoptOpenJDK Installation

Now it is just a matter up updating the settings in your Delphi / RAD Studio IDE. Go to Tools → Options → Deployment → SDK Manager and then select one of your Android SDK (32 or 64-bit) and jump to the Java tab, where you should see something like the image below.

Delphi RAD Studio SDK Manager - Android - Java Tab - Before

If you left your Oracle Java SE JDK installed then you won’t have the yellow triangle because the old JDK is still there. Then use the ellipsis browse button to change it to the path you installed AdoptOpenJDK. Be sure to change all of your Android SDK entries.

Delphi RAD Studio SDK Manager - Android - Java - After

From that point forward you shouldn’t notice any changes. It just works. Both the Oracle SE JDK and AdoptOpenJDK are based on the same source code the functionality is the same.

Alternative Installation

My preferred way to install and update the AdoptOpenJDK is with the ChocolateyChocolatey Package Manager Windows package manager.

  1. Open a PowerShell window with Administrative privileges
  2. Run the following to install Chocolatey
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  3. Then install AdoptOpenJDK 8
    choco install adoptopenjdk8
  4. And in the future when you want to update you just run the following from an elevated command prompt
    choco update adoptopenjdk8 

I’m a huge fan of the Chocolaty package manager (I have a Pro subscription). If you take a look at it I’m sure you will find it very useful.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Director of Delphi Consulting for GDK Software USA. Many software related patents, including swipe and pattern unlock and search engines. First Silver and Gold Delphi badges on Stack Overflow Former Developer Advocate for Embarcadero Technologies. Long time fan of programming, especially with Delphi. Author, Podcaster/YouTuber, Improvisor, Public Speaker, Father, and Friend.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES