Skip to content

Commit

Permalink
package: enable compiling Java sources with JDK v20+ (#272)
Browse files Browse the repository at this point in the history
* package: enable compiling Java sources with JDK v20+

* ci: add Java 20 to the test matrix

* package: also use system provided `zip` if using JDK v20
  • Loading branch information
larpon authored Nov 18, 2023
1 parent ec7b232 commit 04ee8d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/matrix_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04]
java-version: [8,11,15]
java-version: [8,11,15,20]
android-api: [27, 30]
timeout-minutes: 20
env:
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04]
java-version: [8, 15]
java-version: [8, 15, 20]
android-api: [27, 30]
timeout-minutes: 20
env:
Expand Down
31 changes: 24 additions & 7 deletions android/package.v
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,24 @@ fn package_apk(opt PackageOptions) ! {
return error('${error_tag}: error while changing work directory to "${package_path}":\n${err}')
}

mut javac_source_version := '1.7'
mut javac_target_version := '1.7'
if jdk_semantic_version.ge(semver.build(20, 0, 0)) {
javac_source_version = '1.8'
javac_target_version = '1.8'
}

// Compile java sources
if opt.verbosity > 1 {
println('Compiling java sources')
println('Compiling java sources ${javac_source_version}/${javac_target_version}')
}
java_sources := os.walk_ext(os.join_path(package_path, 'src'), '.java')

mut javac_cmd := [
javac,
'-d obj', // NOTE `+obj_path` can be specified
'-source 1.7',
'-target 1.7',
'-source ${javac_source_version}',
'-target ${javac_target_version}',
'-classpath .',
'-sourcepath src',
'-bootclasspath "' + android_runtime + '"',
Expand Down Expand Up @@ -635,8 +642,16 @@ fn package_aab(opt PackageOptions) ! {
util.run_or_error(aapt2_link_cmd)!
}

mut javac_source_version := '1.7'
mut javac_target_version := '1.7'
if jdk_semantic_version.ge(semver.build(20, 0, 0)) {
javac_source_version = '1.8'
javac_target_version = '1.8'
}

// Compile java sources
if opt.verbosity > 1 {
println('Compiling java sources')
println('Compiling java sources ${javac_source_version}/${javac_target_version}')
}
java_sources := os.walk_ext(src_path, '.java')
java_gen_sources := os.walk_ext(os.join_path(package_path, 'gen'), '.java')
Expand All @@ -649,8 +664,8 @@ fn package_aab(opt PackageOptions) ! {

mut javac_cmd := [
javac,
'-source 1.7',
'-target 1.7',
'-source ${javac_source_version}',
'-target ${javac_target_version}',
'-bootclasspath "' + android_runtime + '"',
'-d classes',
'-classpath .',
Expand Down Expand Up @@ -817,7 +832,9 @@ fn package_aab(opt PackageOptions) ! {
// com.android.tools.build.bundletool.model.exceptions.CommandExecutionException: File 'base.zip' does not seem to be a valid ZIP file.
// ...
// Caused by: java.util.zip.ZipException: invalid CEN header (bad signature)
if jdk_semantic_version.le(semver.build(1, 8, 0)) {
if jdk_semantic_version.le(semver.build(1, 8, 0))
|| (jdk_semantic_version.ge(semver.build(20, 0, 0))
&& jdk_semantic_version.lt(semver.build(21, 0, 0))) {
$if !windows {
if opt.verbosity > 1 {
println('Working around Java/bundletool/ZIP64 BUG...')
Expand Down

0 comments on commit 04ee8d8

Please sign in to comment.