skip to Main Content

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 libmain.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:UsersMr. WolfeAppDataLocalAndroidsdkplatformsandroid-34core-for-system-modules.jar.
             > Error while executing process C:Program FilesAndroidAndroid Studiojbrbinjlink.exe with arguments {--module-path C:UsersMr. Wolfe.gradlecachestransforms-34a46fc89ed5f9adfe3afebf74eb8bfebtransformedoutputtempjmod --add-modules java.base --output C:UsersMr. Wolfe.gradlecachestransforms-34a46fc89ed5f9adfe3afebf74eb8bfebtransformedoutputjdkImage --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 = "../.."
    }

2

Answers


  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:UsersusernameDesktopFlutterProjtest> cd android

    PS C:UsersusernameDesktopFlutterProjtestandroid> ./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>AppDataLocalPubCache 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! 😉

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search