发布到 MavenCentral 的库在引入 app 后编译时发生“Could not find :unspecified:.”错误的解决方法

357 阅读1分钟

发布到 MavenCentral 的库在引入 app 后编译时发生“Could not find :unspecified:.”错误的解决方法

问题描述

发布到 MavenCentral 的库在引入 app 后引入正常,相关组件在代码中可以正常调用,但是编译 app 时 gradle 报错:

Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugJavaResource'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find :unspecified:.
     Required by:
         project :app > com.kongzue.xxx:XXX:1.0.0

故障排查

错误大致意思是无法找到 “unspecified”,猜测是 aar 的引用出现问题,检查 MavenCentral 生成的 pom 文件果然发现问题: 存在一个叫做 unspecified 的引用,版本为空。 检查代码,发现 gradle 引用处除了 appcompat 外也就有一个:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
}

猜测是第一句 implementation fileTree(dir: 'libs', include: ['*.jar']) 导致的。

解决问题

删除它重新上传新版本,生成 pom,发现没有 unspecified 了,再次尝试引入 app 编译通过。