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

Fix the diagnostics where there is a JDK version mismatch #1709

Merged
merged 2 commits into from
Nov 9, 2024
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
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
Loading