15

I am having this problem with my android studio, so anytime I ran the actual default flutter project in android studio it runs. as soon as I add packages in the pubspec.yaml I get errors. I am trying to run a project, this project has been running so well for sometime now. all of a sudden when I come back to the project and run it I get this weird error. I asked ChatGPT and it said it was a jdk incompatibility problem. this is the error.


    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

this is what my app/build.gradile looks like;


    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 = "../.."
    }

6 Answers 6

30

Since last 5 days I have the same issue. It is not related to android studio. I have this issue in VS code as well. Could you find a solution. I couldn't yet. While adding some packages this issue occurs. e.g. give, google fonts, etc.

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\aksha\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\aksha\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\temp\jmod --add-modules java.base --output C:\Users\aksha\.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 8s
Error: Gradle task assembleDebug failed with exit code 1

I tried creating a new project, and when adding some packages this issue occurs even for counter app.

UPDATE: https://github.com/flutter/flutter/issues/156558

This solved my issue. https://github.com/flutter/flutter/issues/156304#issuecomment-2397707812 What's done here:

Open android/app/build.gradle and change:

 android {
        ndkVersion = "25.1.8937393"
        ...
   
    compileOptions {
      sourceCompatibility JavaVersion.VERSION_17
      targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

Open android/gradle/wrapper/gradle-wrapper.properties and change:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

Open android/settings.gradle and change:

    id "com.android.application" version "8.3.1" apply false
Sign up to request clarification or add additional context in comments.

1 Comment

what did you put for the compileSdk in app/build.gradle and all the properties under defaultConfig particularly, minSdk, targetSdk
1

I am not using Android Studio for the Flutter project, because I found it convenient to use VS Code. However,

According to you,

I am trying to run a project, this project has been running so well for sometime now. all of a sudden when I come back to the project and run it I get this weird error.

Have you tried the Flutter clean and rebuild? The thing in your case is to make sure that the cache of your build doesn't conflict with the current state of your project build.

In order for me to help you, I did some research to understand how to do it in Android Studio. So here's how: How to Clear Flutter’s Build Cache?

Moreover, I have encountered that before, my project was working at first, but then suddenly introduced an exception when I built specific types of packages such as APK, appbundle, or web.

These are my procedural steps to resolve that issue.

  1. I read the changelog of the plugin I've been using to understand what it could cause to the architecture of my flutter project.

  2. I am reviewing my source code to make sure that I am not using a platform-specific import and function/built-in method.

  3. I am reviewing Android Studio's latest suggestions for the code/configuration that is deprecated to see if there's a high-priority build.gradle configurations which I will use as my reference to my Flutter project build.gradle config. (I am using Visual Studio Code because I was more preferred to use it).

  4. I used to clean and rebuild my project (Flutter project), but I did a unique way in order to address a specific issue-case scenario. I opending a terminal and navigate to android directory; by executing:

PS C:\Users\username\Desktop\FlutterProj\test> cd android
PS C:\Users\username\Desktop\FlutterProj\test\android> ./gradlew clean build

  1. If 1 to 4 is not the cause of producing build exceptions and the build exception persists. Then I deleted the folder directory containing all the dependencies used for my Flutter app. That package dependencies are stored at, C:\Users<Username>\AppData\Local\Pub\Cache And I only perform this when there's no such project I've been working on aside from Flutter development (to not happen to you what happened to me). Then, I rebuild my project. It should be applied only when you are sure that the plugin you've been using in your source code is working and implemented properly (i.e., the project was running properly during the debug mode).

NOTE: It is applicable to me before because I am not really configuring the build.gradle (i.e., adding platform-specific dependencies and so on) as my project did work every time I ran my project in debug mode.

Lastly, you may visit this forum for other way of resolving the build exception: Update flutter dependencies in /.pub-cache

I hope it helps! 😉

2 Comments

I have been clearing caches, I have added jdks I have rebuilt my project from scratch... but anytime I add dependencies I get this error
Okay, I will edit my comment to share my experience regarding that issue.
1

You should update the following properties

android > gradle/wrapper > gradle-wrapper.properties > distributionUrl Replace the URL with this : https://services.gradle.org/distributions/gradle-8.9-all.zip

settings.gradle > plugin Replace it with this : id "com.android.application" version "8.7.1" apply false

Wait for some time and you'll be ready to go if this solution didn't work for you try to find the suitable versions

Comments

0

Another thing, if you're having issues with dependencies, and if you're using Visual Studio Code.

Try to check the OUTPUT tab right next to PROBLEMS (or you can using shortcut commands: Ctrl+Shift+U) There are information about plugins' version you've been using, whether they're compatible with each other or not. It will update the information after by having save changes in the dependencies of pubspec.yaml file.

It is useful for me to understand the compatibility between my project and the plugins dependencies itself.

9 Comments

yh that is the hard part. I found out it is sqflite and path provider that are causing the issue. but I have no idea which version will be compatible. it is driving me nuts
I've been using Android Studio in my recent projects. To be honest, I found it useful in how Android Studio do the work for me in terms of using a dependencies with a corresponding version. When I've decided to use VS Code instead of Android Studio, I found out that it has a similar approach in dealing with plugin and dependencies. I know, it depends on how you added it into your project. But one thing is for sure. It always suggests which version is compatible with your project infrastructure. The only causing the issue sometimes is, if you added a plugin that is not actually you need.
In order for you to relate, lately in my VS Code project with Flutter. I needed to use FCM for my project, I added a plugin firebase_messaging and firebase_core, and then I build an app for apk, it works fine. But when I tried to build for web. It introduces an exception. I spend days in finding solution for it. After days, I've decided to read the article from Firebase website on how to properly integrate it in Flutter project since I am working in cross-platform project. Then I found that the firebase_messaging plugin is redundant, so after I removed it, the exception also resolved.
I strongly advise you don't rush to resolve things in your project, such as build exceptions. When you made several changes, particularly in plugin installation. Don't forget to rebuild your project to always maintain your build in an updated state before testing your specific platform build.
If you're not really sure about it. You can visit the sqflite and path_provider plugins. You have to read the dependencies and changelog under each plugin. They always include the information there if you have something to know regarding on how you properly implement it in your project. Just be sure that it isn't conflicting with your project infrastructure (i.e., Flutter & dart version, JAVA support/target (I hope you get what I mean) etc.
|
0

Following up on @Akshaykumar's solution, I encountered this error: FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':app:checkDebugAarMetadata'.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction An issue was found when checking AAR metadata:

  1. Dependency ':flutter_local_notifications' requires core library desugaring to be enabled for :app. See https://developer.android.com/studio/write/java8-support.html for more details.

To resolve this, add the following to your android/app/build.gradle:

  1. Add the desugaring dependency:
dependencies {
    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.3"
}

Enable Java 17 and desugaring:

gradleCopyandroid {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
        coreLibraryDesugaringEnabled true
    }
}

Comments

-1

I removed the google_fonts from my pubspec.yaml and it worked.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.