运行Dart文件时Android Studio报错,Flutter Doctor检测无异常
问题现象
运行Flutter项目时Android Studio报Gradle编译失败,核心错误为connectivity_plus模块的compileDebugJavaWithJavac任务执行失败,无法解析androidJdkImage配置,具体是jlink.exe处理core-for-system-modules.jar时出错,但flutter doctor检测无异常。
解决方案
清理Gradle缓存
删除用户目录下的.gradle/caches文件夹(如C:\Users\hp\.gradle\caches),重新运行项目让Gradle生成新的缓存文件。调整SDK与JDK版本兼容性
打开SDK Manager卸载Android 34,安装Android 33,然后修改项目build.gradle文件中的compileSdkVersion和targetSdkVersion为33;或者更新Android Studio到最新稳定版,确保内置JBR与Android 34 SDK兼容。修复损坏的SDK文件
删除路径C:\Users\hp\AppData\Local\Android\Sdk\platforms\android-34\core-for-system-modules.jar,回到SDK Manager重新安装Android 34的Platform包。更新connectivity_plus依赖
打开pubspec.yaml,将connectivity_plus版本更新至最新稳定版,执行flutter pub get后重新编译项目。临时禁用JDK Image转换
在项目根目录的gradle.properties中添加配置:android.disableAutomaticComponentCreation=true,再重新运行项目。
内容的提问来源于stack exchange,提问作者Abdelilah

