Gradle failure when building Flutter app: Error while executing JdkImageTransform in Android Studio: Could not resolve all files for configuration
Asked Answered
B

2

5

I recently updated Android Studio to Ladybug and since then I encounter this error when i try to build my app:

Launching lib\main.dart on sdk gphone64 x86 64 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\ilsim\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\ilsim\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\temp\jmod --add-modules java.base --output C:\Users\ilsim\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\jdkImage --disable-plugin system-modules}

What I checked is: flutter doctor:

[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Versione 10.0.22631.4249], locale it-IT)
    • Flutter version 3.24.3 on channel stable at C:\Users\ilsim\Documents\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (4 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

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

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\ilsim\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.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.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] 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)

[√] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 15 (API 35) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Versione 10.0.22631.4249]
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 129.0.2792.79

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

! Doctor found issues in 2 categories.

I've never touched the Gradle configuration files and the code but before the update everything worked fine, also I do not use the package path_provider in my app. So can someone help me solve the problem?

Bigwig answered 7/10 at 8:4 Comment(0)
H
1

Step 1: Flutter clean
Step 2: Flutter pub cache repair
Step 3: Invalidate cache and restart(select the clear VCS Log caches and indexes, delete embedded browser engine cache and coockies)
Step 4: Flutter pub get

Hypothermia answered 7/10 at 8:39 Comment(2)
I also had to go back to JDK 17 (from JDK 21) and update the gradle package to version 8.3. Then everything worked fineBigwig
@Bigwig how did you drop from JDK 21 to 17?Lizbeth
B
6

If this answer didn't solve your problem, try this:

  1. Change this lines in android/app/build.gradle file:
        android {    
        compileSdk 35
        ndkVersion "25.1.8937393"
    
        ///
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }
        kotlinOptions {
            jvmTarget = 17
        }
    }
  1. Change distributionUrl in android/gradle/wrapper/gradle-wrapper.properties file:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
  1. Change these three lines in android/setting.gradle file:
    id "com.android.application" version "8.3.2" apply false
    id "com.google.gms.google-services" version "4.4.2" apply false // only if you are using firebase
    id "org.jetbrains.kotlin.android" version "2.0.20" apply false
  1. Lastly, open android project separately and wait for initial project build, then open Project Structure and set "all" variables in Modules section like it:

Android Studio Project Structure windows


UPDATE: Also set flutter's JDK dir with this command. Dont forget to change directory based on your JDK actual directory.

flutter config --jdk-dir="C:\Program Files\Java\jdk-17"
Burbot answered 16/10 at 16:51 Comment(0)
H
1

Step 1: Flutter clean
Step 2: Flutter pub cache repair
Step 3: Invalidate cache and restart(select the clear VCS Log caches and indexes, delete embedded browser engine cache and coockies)
Step 4: Flutter pub get

Hypothermia answered 7/10 at 8:39 Comment(2)
I also had to go back to JDK 17 (from JDK 21) and update the gradle package to version 8.3. Then everything worked fineBigwig
@Bigwig how did you drop from JDK 21 to 17?Lizbeth

© 2022 - 2024 — McMap. All rights reserved.