Flutter Error : Could not resolve all artifacts for configuration ':image_picker_android:debugUnitTestRuntimeClasspath'

Viewed 14688

The application which I am working on is debugging fine in emulator or in mobiles but when I try to build the apk it gives the following Error:

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                        


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':image_picker_android:debugUnitTestRuntimeClasspath'.
   > Failed to transform bcprov-jdk15on-1.68.jar (org.bouncycastle:bcprov-jdk15on:1.68) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: /home/cicada/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.68/46a080368d38b428d237a59458f9bc915222894d/bcprov-jdk15on-1.68.jar.
         > Failed to transform '/home/cicada/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.68/46a080368d38b428d237a59458f9bc915222894d/bcprov-jdk15on-1.68.jar' using Jetifier. Reason: IllegalArgumentException, message: Unsupported class file major version 59. (Run with --stacktrace for more details.)
           Suggestions:
            - Check out existing issues at https://issuetracker.google.com/issues?q=componentid:460323&s=modified_time:desc, it's possible that this issue has already been filed there.
            - If this issue has not been filed, please report it at https://issuetracker.google.com/issues/new?component=460323 (run with --stacktrace and provide a stack trace if possible).

* 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 19s
Running Gradle task 'assembleRelease'...                           20.7s
Gradle task assembleRelease failed with exit code 1
Process finished with exit code 1
6 Answers

I added following lines in the android directory of app level build.gradle i.e android/app/build.gradle of my project.

   lintOptions {
        disable 'InvalidPackage'
        disable "Instantiatable"
        checkReleaseBuilds false
        abortOnError false
    }

And every thing started to work fine. Check out my Gradle File

Let me help you a little bit in finding the correct place to paste the code

1: Go to your app-level build.grade. enter image description here

2:Scroll down to "android{ " paste this code carefully(not disturbing any other brakets.)

lintOptions {
            disable 'InvalidPackage'
            disable "Instantiatable"
            checkReleaseBuilds false
            abortOnError false
        }

enter image description here

3:run "flutter clean" 4:run "flutter pub get" 5:If you want to build apk of your project then run "flutter build apk"

I hope it works for you.

The solution is actual on 06.06.2022. Adding these lines in pubspec.yaml fixed the problem:

dependency_overrides:
  image_picker_android: 0.8.4+13

The issues lies in image_picker_android being updated to gradle 7.1.2. See their changelog. Following an issue on GitHub you have to update your gradle version like so:

In android/gradle/wrapper/gradle-wrapper.properties update your distributionUrl to

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

and in android/build.gradle change the gradle version to at least 7.1.2

classpath 'com.android.tools.build:gradle:7.1.2

In my case, I had to update my Android Studio for a newer Java version too.

if you are using flutter 3.0 and image_picker, try this:

dependency_overrides:
  image_picker_android: 0.8.4+13

This issue is usually because the gradle plugin is outdated. If your project was created using an older version of flutter the gradle plugin will be old. The actual fix to this issue would be to upgrade the gradle plugin version.

Refer to this issue

You can use android studio to do this for you or just edit the files on your own.

Related