When performing flutter run on my visual studio code, I get the error message below:
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ‘:flutter_plugin_android_lifecycle:compileDebugJavaWithJavac’.
Could not resolve all files for configuration ‘:flutter_plugin_android_lifecycle: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****AppDataLocalAndroidsdkplatformsandroid-34core-for-system-modules.jar.
Error while executing process C:Program FilesAndroidAndroid Studiojbrbinjlink.exe with arguments {–module-path C:Users*****.gradlecachestransforms-34a46fc89ed5f9adfe3afebf74eb8bfebtransformedoutputtempjmod –add-modules java.base –output C:Users******.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 21s
Running Gradle task ‘assembleDebug’… 23.1s
Error: Gradle task assembleDebug failed with exit code 1
I have tried the following solutions:
flutter pub cache repair
flutter clean
flutter pub get
flutter build apk
but even after doing the procedure, I am still stuck at the error.
2
Answers
One of the causes may occur this error may be the mismatch between Gradle version and Android SDK version. I suggest these steps to make sure, we are using right version of Gradle.
make sure to open just the "android" folder not the whole Flutter project with Android Studio.
After downloading and installing Gradle, the error may be gone but if you get the incompatible error, you can follow the recommendations which will be shown on the build section.
If you’ve encountered issues after upgrading to Android Studio LadyBug, here’s how you can resolve them:
Modify settings.gradle File:
Under the plugins section in your settings.gradle file, add the following line:
id "com.android.application" version "8.3.2" apply false
Gradle Plugin Error:
If you encounter any errors related to the Gradle plugin version, update your gradle-wrapper.properties file with the following:
distributionUrl=https://services.gradle.org/distributions/gradle-8.4-all.zip
After making these changes, clean and rebuild your project to ensure everything compiles correctly.
You can read more on this issue on this github : credits