无法解析 ':app@debug/compileClasspath' 的依赖关系:无法转换工件 'lifecycle-viewmodel.aar

Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform artifact 'lifecycle-viewmodel.aar

我使用最新的 Android Studio 3.5 版本(Android Gradle 插件 3.5.0)。当我尝试编译时收到此错误:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform artifact 'lifecycle-viewmodel.aar (androidx.lifecycle:lifecycle-viewmodel:2.1.0)' to match attributes {artifactType=jar}. Show Details Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Failed to transform artifact 'lifecycle-viewmodel.aar (androidx.lifecycle:lifecycle-viewmodel:2.1.0)' to match attributes {artifactType=jar}. Show Details Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Failed to transform artifact 'lifecycle-viewmodel.aar (androidx.lifecycle:lifecycle-viewmodel:2.1.0)' to match attributes {artifactType=jar}. Show Details Affected Modules: app

能否分享您的 build.gradle 文件?虽然我不确定,但它可能有效

解决方案 1:转到 "File"。单击使缓存无效/重新启动。再次点击 Invalidate Cache / Restart

解决方案 2:更改

应用插件:'com.android.application' 到 应用插件:'com.android.library'

方案三: dependencies中一一注释掉,尝试运行

只需重命名您的库或从重构中复制您的库名称并将其粘贴到 build.gradle。

就我而言,更新 gradle.properties 有效。

之前:

org.gradle.jvmargs=-Xmx1536M

之后:

org.gradle.jvmargs=-Xmx4096M