V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yiyiniu
V2EX  ›  Flutter

V 友们, Flutter 编译报错可能是什么原因

  •  
  •   yiyiniu · 3 天前 · 964 次点击

    服务器版本、环境版本如下:

    java version "21.0.7" 2025-04-15 LTS Java(TM) SE Runtime Environment (build 21.0.7+8-LTS-245) Java HotSpot(TM) 64-Bit Server VM (build 21.0.7+8-LTS-245, mixed mode, sharing) Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [版本 10.0.19041.264], locale zh-CN) [√] Windows Version (10 专业版 64 位, 2004) [√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3) [√] Android Studio (version 2024.3) [√] VS Code (version 1.99.3) [√] Connected device (3 available) [√] Network resources

    执行完命令:flutter build apk

    报错如下:

    FAILURE: Build failed with an exception.
    • What went wrong: Could not open cp_settings generic class cache for settings file 'C:\jk-katalon\workspace\XXXX\XXXX-app\android\settings.gradle' (C:\Users\cs.gradle\caches\8.0\scripts\8ju52g7d2hqvl85b219kdzjzv).

    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.

    BUILD FAILED in 8s Running Gradle task 'assembleRelease'... 9.3s

    ┌─ 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:\jk-katalon\workspace\XXXX\XXXX-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 │ │ │ │ │ └─────────────────────────────────────────────────────────────────────────────────────────────────┘

    8 条回复    2025-05-05 20:16:39 +08:00
    joyoyao
        1
    joyoyao  
       3 天前
    jdk 版本改低点
    w568w
        2
    w568w  
       2 天前
    这不是说得很清楚了,你运行 Gradle 的 Java 版本和 Gradle 支持的版本不匹配
    yiyiniu
        3
    yiyiniu  
    OP
       2 天前
    @w568w 怎么修改呢?请教
    w568w
        4
    w568w  
       2 天前
    @yiyiniu 就按照上面日志的 Flutter fix 里写的操作啊。先看看你的 Gradle 是什么版本,然后对照 Compatibility Matrix 看看需要什么 Java 版本。Java 21 只有 Gradle 8.4 以后才支持,要么升级 Gradle ,要么降级 Java
    guoxiaowen
        5
    guoxiaowen  
       2 天前
    装个低版本的 jdk
    cyersvet
        6
    cyersvet  
       2 天前 via Android
    lemos1235
        7
    lemos1235  
       2 天前
    升级 gradle ,修改 android/gradle/wrapper/gradle-wrapper.properties 。
    或者用旧的 flutter 版本
    gavinhome
        8
    gavinhome  
       2 天前
    一般都是版本不匹配问题导致的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4141 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 04:09 · PVG 12:09 · LAX 21:09 · JFK 00:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.