You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio编译依赖错误:无法转换annotation-experimental.aar

问题描述

我是Kotlin新手,刚在Android Studio 3.4.1中创建了首个Kotlin应用,但应用构建失败无法启动。已尝试执行Invalidate Caches/Restart操作但无效。

环境信息:

  • JDK版本:11.0.16.1

构建错误信息:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform artifact 'annotation-experimental.aar (androidx.annotation:annotation-experimental:1.3.0)' to match attributes {artifactType=jar}
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Failed to transform artifact 'annotation-experimental.aar (androidx.annotation:annotation-experimental:1.3.0)' to match attributes {artifactType=jar}
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Failed to transform artifact 'annotation-experimental.aar (androidx.annotation:annotation-experimental:1.3.0)' to match attributes {artifactType=jar}
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Failed to transform artifact 'annotation-experimental.aar (androidx.annotation:annotation-experimental:1.3.0)' to match attributes {artifactType=jar}
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Failed to transform artifact 'annotation-experimental.aar (androidx.annotation:annotation-experimental:1.3.0)' to match attributes {artifactType=jar}
Affected Modules: app

当前依赖配置:

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   implementation 'androidx.appcompat:appcompat:1.5.1'
   implementation 'androidx.core:core-ktx:1.9.0'
   implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'androidx.test:runner:1.4.0'
   androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
解决方案
  • 降低依赖版本适配旧版AS:Android Studio 3.4.1版本较旧,和你使用的高版本AndroidX依赖不兼容。把androidx.appcompat:appcompat降到1.1.0,androidx.core:core-ktx降到1.0.2,androidx.constraintlayout:constraintlayout降到1.1.3,同步后重新构建。
  • 显式指定兼容版本并排除冲突:在依赖中添加低版本的annotation-experimental,同时排除其他依赖传递过来的高版本:
    implementation 'androidx.annotation:annotation-experimental:1.0.0'
    implementation('androidx.appcompat:appcompat:1.5.1') {
        exclude group: 'androidx.annotation', module: 'annotation-experimental'
    }
    implementation('androidx.core:core-ktx:1.9.0') {
        exclude group: 'androidx.annotation', module: 'annotation-experimental'
    }
    
  • 升级Android Studio:旧版AS对高版本AndroidX依赖的支持有限,如果条件允许,直接升级到Arctic Fox及以上版本,能从根源解决兼容性问题。
  • 核对JDK配置:在File > Project Structure > SDK Location中确认Android Studio的JDK路径指向11.0.16.1,避免IDE和系统JDK版本不匹配。

内容的提问来源于stack exchange,提问作者nit21

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 23:40:36