项目场景:
gradle构建失败
问题描述
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ‘:app:checkDebugAarMetadata’.
Could not resolve all files for configuration ‘:app:debugRuntimeClasspath’.
Failed to transform annotation-experimental-1.4.0.aar (androidx.annotation:annotation-experimental:1.4.0) to match attributes {artifactType=android-aar-metadata, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
Execution failed for JetifyTransform: C:\Users\cwt.gradle\wrapper\dists\gradle-6.5-bin\caches\modules-2\files-2.1\androidx.annotation\annotation-experimental\1.4.0\c7a2038d831d0cfbfb9a440890b287c2e839ecf\annotation-experimental-1.4.0.aar.
Failed to transform ‘C:\Users\cwt.gradle\wrapper\dists\gradle-6.5-bin\caches\modules-2\files-2.1\androidx.annotation\annotation-experimental\1.4.0\c7a2038d831d0cfbfb9a440890b287c2e839ecf\annotation-experimental-1.4.0.aar’ using Jetifier. Reason: IllegalArgumentException, message: Unsupported class file major version 61. (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).
原因分析:
创建空项目时,默认AndroidX库版本('androidx.appcompat:appcompat:1.7.0‘mplementation ‘com.google.android.material:material:1.12.0’)和jdk(1.8)版本不匹配
解决方案:
降低androidx.appcompat:appcompat版本(1.2.0)implementation 'com.google.android.material:material版本:(1.2.1)
dependencies {
implementation ‘com.google.android.material:material:1.2.1’
//implementation ‘com.google.android.material:material:1.12.0’
implementation ‘androidx.appcompat:appcompat:1.2.0’
//implementation ‘androidx.appcompat:appcompat:1.7.0’