Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile OpenJDK 11 on an M1 Macbook?

I want to compile the OpenJDK 11 for an M1 MacBook.

First, I tried to use the Zulu JDK, but I did not find out a way to compile it.

Then, I tried to try compile OpenJDK on an M1, but this reports an error when I run sh configure.

The error is:

configure: The tested number of bits in the target (64) differs from the number of bits expected to be found in the target (32) configure: error: Cannot continue.

So, how can I compile it?

like image 343
rainbowecho Avatar asked Jul 13 '21 07:07

rainbowecho


People also ask

Does Java JDK work on Mac M1?

The brew formula for openjdk is also installing a compatible Apple M1 JDK build. For managing different Java versions, sdkman or jEnv is an excellent option. For those lucky developers that have the chance to work and experiment with the GraalVM, the support for Apple M1 has also landed.

Which Java JDK should I download for Mac M1?

Installing the JDK on macOS To install the JDK on macOS: Download the JDK . dmg file, jdk-16.


3 Answers

tl;dr

I want to compile jdk in M1 MacBook.

Do not try to compile OpenJDK. Codebase is large and complicated. And no need, as others provide binaries & installers.

For a Mac using Apple Silicon rather than Intel x86-64, I suggest obtaining a distribution of Java 17 for macOS / AArch64, released 2021-09, from any of several vendors.

Or, use a build of earlier versions of Java ported to Apple Silicon by various vendors. For example, Azul Systems announced 2020-11 plans to ship builds of OpenJDK 8 and 11 for Apple Silicon, ARM-based Macs. I see downloads available now from that company for Java 11.0.13+8 on both Intel Macs and Apple Silicon Macs.

Details

Few of us ever compile the very large and complicated codebase of OpenJDK. Instead, we look to any of several vendors providing builds and installers.

Java 17 was released 2021-09. OpenJDK officially supports macOS on Apple Silicon: JEP 391: macOS/AArch64 Port. You have your choice of builds/installers from any of several vendors such as SAP, Red Hat/IBM, BellSoft, Azul Systems, Oracle, Adoptium/AdoptOpenJDK, Microsoft, Amazon, Pivotal, and more. These builds/installers will be based largely or entirely on the OpenJDK codebase.

FYI, Java 17 is the latest long-term support (LTS) version, to be supported for many years.

I myself am have been using first the early-access Java 17, and now the official Java 17 release, on my M1 MacBook Pro with IntelliJ 2021.x and Maven on Big Sur. Working well, no problems. Java 18 Early Access is now available for both Intel Macs and Apple Silicon Macs.

As commented, your specific error is likely due to you compiling for 32-bit ARM rather than 64-bit ARM used by Apple for their M1 chip.

If you insist on attempting to compile OpenJDK, I suggest examining the open-sourced tooling at Adoptium/AdoptOpenJDK. The tooling for building early-access builds at the OpenJDK site may also be open-sourced but I don’t know for certain.

like image 67
Basil Bourque Avatar answered Oct 24 '22 03:10

Basil Bourque


I had install Android Studio Version, please see screenshot enter image description here

I was getting issues (install JAVA ) while building the Flutter Application, So I had installed JDK 17 but it was not compatible.

I had went AZUL

I installed first .dmg file. Please see screenshot enter image description here

It will solve the issue for building Gradle and APK issue with M1 Mac

like image 38
Anil Gupta Avatar answered Oct 24 '22 04:10

Anil Gupta


You can build OpenJDK 11.0.12 on an M1 MacBook, with the help of Homebrew, by running:

brew install --build-from-source --verbose openjdk@11

Xcode is a prerequisite, you can download it from there https://developer.apple.com/download/more/ (Apple ID needed).

You probably also have to run:

xcode-select --install
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

I've tested it and it builds perfectly.

like image 2
Ortomala Lokni Avatar answered Oct 24 '22 04:10

Ortomala Lokni