Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package: enable compiling Java sources with JDK v20+ #272

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading