keymanapp / keyman

Keyman cross platform input methods system running on Android, iOS, Linux, macOS, Windows and mobile and desktop web
https://keyman.com/
Other
404 stars 112 forks source link

feat(android) Update to Java 11 #2293

Closed darcywong00 closed 1 year ago

darcywong00 commented 5 years ago

in #2279 @safolit had started the process of updating the Android build to use Java 11.

Though we're staying with Java 8 for now, I'm documenting the steps for when this happens.

Note, in order to run robolectric for Android SDK 29, we'll need to update Java (see robolectric.properties)

Java SE Development Kit 11 (Java 9 or newer)

Install Java

It is recommended to use openJDK because of oracle license issues. Tested with latest release for openJDK 11 from https://github.com/ojdkbuild/ojdkbuild

  1. Download and unpack the zip archive
  2. On Windows: use the default java path C:\Program Files\Java to avoid error message

    "Error 0x80010135 Path Too Long"

  3. Aso set an environment variable for JAVA_HOME e.g C:\Program Files\Java\openjdk-11.0.5.10-1
darcywong00 commented 3 years ago

Per https://android-developers.googleblog.com/2020/12/announcing-android-gradle-plugin.html

Java 11 is a pre-req for using Gradle plugin 7.0 (#4603)

darcywong00 commented 3 years ago

We don't need Java 11 for Keyman 15.0. Deferring to Future

rc-swag commented 2 years ago

Or the appropriate version of Java at the time.

darcywong00 commented 1 year ago

I've done preliminary work to update the Android projects to build with MS OpenJDK 11.

Issue with multiple versions of Java

One dilemma with CI is the builds depend on the environment variable JAVA_HOME to specify the Java version which is currently set to Java 8 for stable-16.0

Workaround with sdkman

It's possible to use sdkman to control what version of Java gets used for a build. Note: on Windows GitBash, I had to edit the setup script to remove the checks for unzip and zip.

After sdkman is installed, it can install Java as

sdk install java 11.0.18-ms # This installs MS OpenJDK 11

sdk install java 8.0.302-open # This installs Java 8 (Java.net)

Then to set the Java version for a build:

sdk default java 8.0.302-open

or

sdk default java 11.0.18-ms

Tradeoffs of using sdkman

sdkman is a bash script that needs to be initialized, and uses unbound variables.

I've had to do a non-standard builder script intro:

#!/usr/bin/env bash
#
# Build Keyman Engine for Android, Keyman for Android, OEM FirstVoices Android app,
# Samples: KMsample1 and KMSample2, Test - KeyboardHarness

source "$HOME/.sdkman/bin/sdkman-init.sh"

#set -x
set -eu
...

  # OpenJDK 11 defined in .sdkmanrc (#)
  set +u
  sdk env
  set -u
darcywong00 commented 1 year ago

Discussing w/ @mcdurdin , instead of sdkman we can set the environment vars JAVA_HOME_8 JAVA_HOME_11 and have the builder script export JAVA_HOME accordingly...

But a more consolidated look at dependences will probably be needed (whole sprint effort from the team I think)