Skip to content

Commit

Permalink
Fix the diagnostics where there is a JDK version mismatch (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan authored Nov 9, 2024
1 parent 2ff68a9 commit b4f2364
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkgs/jnigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 24 additions & 5 deletions pkgs/jnigen/lib/src/tools/android_sdk_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b4f2364

Please sign in to comment.