Flutter项目添加依赖后:path_provider_android:compileDebugJavaWithJavac执行失败
Flutter Build Fail: JDK Compatibility Issue with jlink.exe After Adding Dependencies
Problem
My default Flutter project runs without issues, but adding any dependency to pubspec.yaml triggers a build failure. Even previously working projects now throw this error on restart. The core issue appears to be JDK compatibility related to the jlink.exe tool.
Error Log
Launching lib\main.dart on AOSP on IA Emulator in debug mode... Running Gradle task 'assembleDebug'... FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':path_provider_android:compileDebugJavaWithJavac'. > Could not resolve all files for configuration ':path_provider_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: C:\Users\Mr. Wolfe\AppData\Local\Android\sdk\platforms\android-34\core-for-system-modules.jar. > Error while executing process C:\Program Files\Android\Android Studio\jbr\bin\jlink.exe with arguments {--module-path C:\Users\Mr. Wolfe\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\temp\jmod --add-modules java.base --output C:\Users\Mr. Wolfe\.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 9s Error: Gradle task assembleDebug failed with exit code 1
app/build.gradle Configuration
plugins { id "com.android.application" id "kotlin-android" // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id "dev.flutter.flutter-gradle-plugin" } android { namespace = "com.example.new_flutter" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8 } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "com.example.new_flutter" // You can update the following values to match your application needs. // For more information, see: https://flutter.dev/to/review-gradle-config. minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion // multiDexEnabled true versionCode = flutter.versionCode versionName = flutter.versionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.debug } } } flutter { source = "../.." }
Solutions
- Verify Android Studio JDK Version
The built-in JetBrains Runtime (JBR) may conflict with Android SDK 34's system modules. Switch to JDK 11:- Open Android Studio →
File→Project Structure→SDK Location - Set
JDK locationto either the embedded JDK or a manually installed JDK 11 path
- Open Android Studio →
- Configure Gradle JVM Home
Add or update this line in your project's rootgradle.properties:
Replace the path with your actual JDK 11 installation if using an external JDKorg.gradle.java.home=C:\\Program Files\\Android\\Android Studio\\jbr - Clean Gradle Caches
Remove cached artifacts to eliminate stale build data:flutter clean # For Linux/Mac rm -rf .gradle/ # For Windows rmdir /s .gradle flutter pub get - Check Dependency Compatibility
Some third-party dependencies require specific JDK versions. Review the documentation for the dependencies you added to confirm if version adjustments are needed
内容的提问来源于stack exchange,提问作者Fred_Wolfe
相关产品推荐
相关产品推荐

