From b4f2364e373db5e7f534a9881ab20d5ee865962d Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Fri, 8 Nov 2024 16:55:34 -0800 Subject: [PATCH] Fix the diagnostics where there is a JDK version mismatch (#1709) --- pkgs/jnigen/CHANGELOG.md | 1 + .../lib/src/tools/android_sdk_tools.dart | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkgs/jnigen/CHANGELOG.md b/pkgs/jnigen/CHANGELOG.md index 2cedb99b5..39f93a42f 100644 --- a/pkgs/jnigen/CHANGELOG.md +++ b/pkgs/jnigen/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug where if multiple jars have classes within the same package, only one of them gets generated. - Fixed a bug where it would be possible for a type class inference to fail. +- Improve the diagnostics when gradle fails when `bin/jnigen` is run. ## 0.12.1 diff --git a/pkgs/jnigen/lib/src/tools/android_sdk_tools.dart b/pkgs/jnigen/lib/src/tools/android_sdk_tools.dart index f1ea1462d..a1016622e 100644 --- a/pkgs/jnigen/lib/src/tools/android_sdk_tools.dart +++ b/pkgs/jnigen/lib/src/tools/android_sdk_tools.dart @@ -203,11 +203,30 @@ task $_gradleGetSourcesTaskName(type: Copy) { } if (procRes.exitCode != 0) { final inAndroidProject = - (androidProject == '.') ? '' : ' in $androidProject'; - throw GradleException('\n\ngradle exited with status ' - '${procRes.exitCode}\n. This can be because the Android build is not ' - 'yet cached. Please run `flutter build apk`$inAndroidProject and try ' - 'again\n'); + (androidProject == '') ? '' : ' in $androidProject'; + throw GradleException('''\n\nGradle execution failed. + +1. The most likely cause is that the Android build is not yet cached. + +Run `flutter build apk`$inAndroidProject and try again. + +2. If the Gradle output includes text like this: + +* What went wrong: +Execution failed for task ':gradle:compileGroovy'. +> BUG! exception in phase 'semantic analysis' ... Unsupported class file major version + +Then the JDK versions used by jnigen and flutter are not compatible. Try +changing the default JDK version e.g. with `export JAVA_VERSION=11` on macOS and +`sudo update-alternatives --config java` on Ubuntu. + +GRADLE OUTPUT: +-------------------------------------------------------------------------------- + +${procRes.stderr} + +-------------------------------------------------------------------------------- +'''); } // Record both stdout and stderr of gradle. log.writeSectionToFile('Gradle logs ($stubName)', procRes.stderr);