I pulled a team’s project that is made in Flutter from Git and for some reason when building the app (pressing the green arrow in Android Studio and running main.dart) I get the following message:
What went wrong:
Execution failed for task ':biometric_storage:kaptGenerateStubsDebugKotlin'.
> Could not resolve all files for configuration ':biometric_storage:kapt'.
> Failed to transform moshi-1.13.0.jar (com.squareup.moshi:moshi:1.13.0) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=8, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for JetifyTransform: C:UsersUserName.gradlecachesmodules-2files-2.1com.squareup.moshimoshi1.13.0da685586facab9eb5c4fb630ce248be14e7da21bmoshi-1.13.0.jar.
> Failed to transform 'C:UsersUserName.gradlecachesmodules-2files-2.1com.squareup.moshimoshi1.13.0da685586facab9eb5c4fb630ce248be14e7da21bmoshi-1.13.0.jar' using Jetifier. Reason: Unsupported class file major version 60. (Run with --stacktrace for more details.)
My build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.google.gms:google-services:4.3.5'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext.kotlin_version = '1.4.31'
My gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip
Other maybe relevant info
Fluter Android Studio plugin 63.2.1
Dart Android Studio plugin 203.8452
Dart 2.15.1
Flutter 2.8.1
Nobody on my team gets this message so I suspect It has to do with some local configuration difference or maybe I have a different version of some program. Also, I can’t update Gradle because that causes some other problems.
EDIT: After clearing the cache all of my teammates, got this error.
3
Answers
NOTE: I am the one who asked this question. The following solutions are independent and you can try just one of them or you can combine them. Choose the one that looks simpler and if that works then there is no need for the other ones.
SOLUTION 1
Try ignoring that one .jar that is causing the problem. You can do this by editing file "gradle.properties". Add
android.jetifier.blacklist
orandroid.jetifier.ignorelist
(LINK TO RELATED QUESTION) depending on the version of Android Gradle plugin version that you are using (to check which version you use, go to your build.gradle and checkcom.android.tools.build:gradle:X.Y.Z
). If you use anything before 7.0.0 useandroid.jetifier.blacklist
and after useandroid.jetifier.ignorelist
.I use 3.6.0 so for me
android.jetifier.blacklist
works andandroid.jetifier.ignorelist
does not.SOLUTION 2
Try updating gradle and android gradle plugin to version 7. I did not try this and I can't because this isn't my personal project, but if you can go for it. Why I think upgrading will help? Well this github issue talks about that.
SOLUTION 3
The following solution doesn't make any sense (at least to me, if someone can explain why this fixes the problem please do), but for some strange reason it works.
I add a new library called bye-bye-jetifier because my idea was that I should turn off jetifier. Prior to turning it off I have to check if I have any dependence that uses outdated code (the code that is not AndroidX) hence I decided to install bye-byte-jetifier. After installing my build.gradle looked like this. After running with the following config the problem was gone.
Note that I didn't even apply the plugin (like the offical guide on bye-bye-jetifier says), that makes this solution even more confusing.
file: "gradle.properties" (Project Properties)
adding line below
You can also exclude moshi library from all the project
Write this in build.gradle(app)
Use carefully only when you know you don’t use this library!