flutter / website

Flutter documentation web site
https://docs.flutter.dev
Other
2.83k stars 3.24k forks source link

gradle build fail #11296

Open KubasuIvanSakwa opened 1 month ago

KubasuIvanSakwa commented 1 month ago

Page URL

https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide/

Page source

https://github.com/flutter/website/tree/main/src/content/release/breaking-changes/android-java-gradle-migration-guide.md

Describe the problem

I am using flutter 3.24.3 and java version that android studio is using is 24, so I should upgrade to gradle 8.5 but when I run the commands the build fails, any help

Expected fix

how can I updgrade the gradle on my apps

Additional context

No response

I would like to fix this problem.

Chaos02 commented 1 month ago

my android studio recently updated to JDK 21 and all my builds now fail. I'm at my witts end! gradle compatibility chart says for 21 I should use gradle 8.4/8.5 but then my builds still fail. Flutter says to use up to gradle 7.6.1 still failing because Android studio JDK is 21:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...

FAILURE: Build failed with an exception.

* What went wrong:
Could not open cp_settings generic class cache for settings file 'C:\Users\mn\source\repos\pizzaboy-app\android\settings.gradle' (C:\Users\mn\.gradle\caches\7.6.1\scripts\1czsxy78qmi5m0geiy8w9l81h).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
Running Gradle task 'assembleDebug'...                              3,5s

┌─ Flutter Fix ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ 
│ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle.                                                                                                               │
│                                                                                                                                                                                                                         │ 
│ If you recently upgraded Android Studio, consult the migration guide at https://flutter.dev/to/java-gradle-incompatibility.                                                                                             │ 
│                                                                                                                                                                                                                         │ 
│ Otherwise, to fix this issue, first, check the Java version used by Flutter by running `flutter doctor --verbose`.                                                                                                      │ 
│                                                                                                                                                                                                                         │ 
│ Then, update the Gradle version specified in C:\Users\mn\source\repos\pizzaboy-app\android\gradle\wrapper\gradle-wrapper.properties to be compatible with that Java version. See the link below for more information on │ 
│ compatible Java/Gradle versions:                                                                                                                                                                                        │ 
│ https://docs.gradle.org/current/userguide/compatibility.html#java                                                                                                                                                       │ 
│                                                                                                                                                                                                                         │ 
│                                                                                                                                                                                                                         │ 
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ 
Error: Gradle task assembleDebug failed with exit code 1

flutter doctor --verbose        
[√] Flutter (Channel beta, 3.26.0-0.1.pre, on Microsoft Windows [Version 10.0.22631.4317], locale de-DE)
    • Flutter version 3.26.0-0.1.pre on channel beta at C:\Users\mn\source\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee624bc4fd (6 weeks ago), 2024-09-10 17:41:06 -0500
    • Engine revision 059e4e6d8f
    • Dart version 3.6.0 (build 3.6.0-216.1.beta)
    • DevTools version 2.39.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\mn\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.0 Preview 3.0)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Preview
    • Visual Studio Community 2022 version 17.12.35410.144
    • The current Visual Studio installation is a pre-release version. It may not be supported by Flutter yet.
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] VS Code (version 1.94.2)
    • VS Code at C:\Users\mn\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.98.0

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 15 (API 35) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22631.4317]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 130.0.6723.59
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 130.0.2849.46
    ! Device R58NB1S15PR is not authorized.
      You might need to check your device for an authorization dialog.

[√] Network resources
    • All expected network resources are available.

• No issues found!
Chaos02 commented 1 month ago

I was able to resolve this by using flutter config --jdk-dir=