You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目编译失败:sqflite_android模块Gradle错误求助

Flutter调试模式编译失败(sqflite_android:compileDebugJavaWithJavac 错误)

更新Android Studio、Flutter及相关依赖后,将Flutter项目运行到moto e40设备的调试模式时出现编译失败,具体错误信息如下:

Launching lib/main.dart on moto e40 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sqflite_android:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':sqflite_android:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: /home/user/Documents/programmation/Android/sdk/platforms/android-34/core-for-system-modules.jar.
         > Error while executing process /home/user/Downloads/rpms/archives/android-studio.new/jbr/bin/jlink with arguments {--module-path /home/user/.gradle/caches/transforms-3/4a46fc89ed5f9adfe3afebf74eb8bfeb/transformed/output/temp/jmod --add-modules java.base --output /home/user/.gradle/caches/transforms-3/4a46fc89ed5f9adfe3afebf74eb8bfeb/transformed/output/jdkImage --disable-plugin system-modules}

* 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 5s
Error: Gradle task assembleDebug failed with exit code 1

已尝试以下无效方案:

  • 删除~/.gradle/caches
  • 删除~/.gradle
  • 删除~/.pub-cache
  • 回退至旧版Android Studio
  • 执行pub remove/add sqflite

可行解决方案

1. 指定兼容的JDK路径

Gradle使用的内置JBR可能与Android 34的系统模块不兼容,手动在项目中指定JDK 11+路径:
在项目的android/gradle.properties文件中添加:

org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64  # 替换为你本地JDK实际路径

2. 更新Android Gradle插件与Gradle版本

在项目的android/build.gradle文件中,更新Android Gradle插件到最新稳定版:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:8.2.2'  // 替换为最新稳定版
    }
}

同步项目后,按照提示更新Gradle wrapper到对应版本。

3. 升级sqflite依赖到兼容版本

在pubspec.yaml中指定sqflite的最新兼容版本:

dependencies:
  sqflite: ^2.3.3  // 确认是适配Flutter及Android 34的版本

执行flutter pub get同步依赖。

4. 彻底清理并重新构建

执行以下命令清理缓存后重新构建:

flutter clean
flutter pub get
cd android
./gradlew clean assembleDebug --no-build-cache

内容的提问来源于stack exchange,提问作者michel duturfu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 07:32:06