I tried to compile our mapbox-java sdk on my Macbook, and ran into a versioning error:
$ make build-config ./gradlew compileBuildConfig Starting a Gradle Daemon (subsequent builds will be faster) > Task :samples:compileBuildConfig FAILED /Users/username/Workspace/mapbox-java/samples/build/gen/buildconfig/src/main/com/mapbox/sample/BuildConfig.java:4: error: cannot access Object public final class BuildConfig ^ bad class file: /modules/java.base/java/lang/Object.class class file has wrong version 56.0, should be 53.0 Please remove or make sure it appears in the correct subdirectory of the classpath. 1 error
I had installed Java via Homebrew Cask, the normal way to install developer things on macOS. Running
brew cask install java gets the
java command all set up for you, but what version is that?
$ java -v Unrecognized option: -v Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. # c'mon java, really :/ smh $ java --version openjdk version "12" 2019-03-19 OpenJDK Runtime Environment (build 12+33) OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing) $ brew cask info java java: 12.0.1,69cfe15208a647278a19ef0990eea691 https://jdk.java.net/ /usr/local/Caskroom/java/10.0.1,10:fb4372174a714e6b8c52526dc134031e (396.4MB) /usr/local/Caskroom/java/12,33 (64B) From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rb ==> Name OpenJDK Java Development Kit ==> Artifacts jdk-12.0.1.jdk -> /Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk (Generic Artifact)
Which is cool.
56.0 are basically the same number.
So I guess I need a lower version of Java. No idea what version of Java will get me this
53.0 "class file," but let's try the last release. Multiple versions means you need a version manager, and it looks like jenv is Java's version manager manager.
$ brew install jenv $ eval "$(jenv init - zsh)" $ jenv enable-plugin export $ jenv add $(/usr/libexec/java_home) $ jenv versions * system (set by /Users/andrewevans/.jenv/version) 12 openjdk64-12
Jenv can't build or install Java / OpenJDK versions for you, so you have to do that separately via Homebrew, then "add" those versions via
jenv add /Some/System/Directory , because java. Also, the oh-my-zsh plugin doesn't seem to quite work, as it doesn't set the
JAVA_HOME env var. I had to manually add the "jenv init" and "enable-plugin" to my shell init scripts.
Anyway, let's try Java 11, as 11 is slightly less than 12 and 53 is slightly less than 56.
$ brew tap homebrew/cask-versions $ brew cask install java11 $ jenv add /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home $ jenv local 11.0 $ jenv shell 11.0
Had to add both of the latter
jenv commands, as I guess
jenv local only creates the
.java-version file and doesn't actually set
JAVA_HOME . Sadly
11.0 is not
53.0 , so I still got basically the same error when I ran
make build-config .
After asking my coworkers, Android and our
mapbox-java repo uses JDK 8. You could install this via a cask called, funnily enough,
java8 . Except Oracle torpedoed it. Sounds like they successfully ran the "embrace, extend, extinguish" playbook on the "open" OpenJDK, though I am not a Java and thus do not fully understand the insanity of these versions and licensing issues). tl;dr Homebrewers had to remove the
Homebrewers seemed to prefer AdoptOpenJDK, which is a perfectly cromulent name and doesn't at all add to the confusion of the dozens of things named "Java." So let's get that installed:
$ brew cask install homebrew/cask-versions/adoptopenjdk8 $ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home $ cd ~/Workspace/mapbox-java $ jenv local 1.8 $ jenv shell 1.8 # apparently 'jenv local' wasn't enough?? $ jenv version 1.8 (set by /Directory/.java-version) $ java -v Unrecognized option: -v Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. # right, forgot about that, jeebus java please suck less $ java --version Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. # wtf java srsly?! $ java -version openjdk version "1.8.0_212" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode) # farking thank you finally $ make build-config
This seemed to be the right version, and the
make build-config command succeeded this time. JDK
53.0 are pretty similar numbers, so in retrospect this should've been obvious. And AdoptOpenJDK has more prefixes before "Java," so I probably should've realized that was the "real" Java.
Anyway, now I can compile the SDK without having to have installed IntelliJ IDEA or Android Studio, which both seemed kinda monstrous and who knows what the hell they'd leave around my system. Goooooood times.