导入Mumla-3.6.3项目时:libraries:humla依赖解析失败求助
解决Mumla-3.6.3项目中
:libraries:humla依赖解析失败问题 问题概述
导入Mumla-3.6.3到Android Studio Electric Eel后,同步时出现警告Unable to resolve dependency for ':app@betaDebugUnitTest/compileClasspath': Could not resolve project :libraries:humla.,执行Make Project时触发错误:
Could not determine the dependencies of task ':app:compileBetaDebugJavaWithJavac'. > Could not resolve all task dependencies for configuration ':app:betaDebugCompileClasspath'. > Could not resolve project :libraries:humla. Required by: project :app > No matching configuration of project :libraries:humla was found. The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'release' with value 'beta' but: - None of the consumable configurations have attributes.
核心原因
:libraries:humla模块未配置与app模块匹配的构建属性(buildType、productFlavor),导致Gradle无法找到对应配置的依赖变体。
解决方案
方案1:给humla模块添加Android库兼容配置
如果:libraries:humla是Android库模块,修改其build.gradle,添加与app模块一致的flavor和buildType配置:
apply plugin: 'com.android.library' android { compileSdkVersion 31 flavorDimensions "release" defaultConfig { minSdkVersion 14 targetSdkVersion 31 } productFlavors { official { dimension "release" } donation { dimension "release" } beta { dimension "release" } } buildTypes { release {} debug {} } } dependencies { // 保留humla原有依赖 }
方案2:修改app模块的依赖配置(针对纯Java模块的humla)
如果:libraries:humla是纯Java模块,无法设置Android专属属性,调整app模块的依赖声明,强制指定匹配的配置:
dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation project(":libraries:humla") { // 指定目标配置为Java模块默认的api配置 targetConfiguration = "api" // 手动匹配app模块的属性要求 attributes { attribute( com.android.build.api.attributes.BuildTypeAttr, project.objects.named(com.android.build.api.attributes.BuildTypeAttr, 'debug') ) attribute('release', project.objects.named('release', 'beta')) } } // 保留其他依赖... }
方案3:统一子项目构建配置(全局生效)
在项目根目录的build.gradle中添加全局配置,确保所有Android模块使用一致的flavor和buildType:
subprojects { afterEvaluate { project -> if (project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('com.android.application')) { project.android { flavorDimensions "release" productFlavors { official { dimension "release" } donation { dimension "release" } beta { dimension "release" } } buildTypes { release {} debug {} } } } } }
收尾操作
完成配置修改后:
- 点击Android Studio工具栏的
Sync Project with Gradle Files按钮同步项目 - 执行
File -> Invalidate Caches...,选择Invalidate and Restart清理缓存并重启IDE
内容的提问来源于stack exchange,提问作者XCosmo
相关产品推荐
相关产品推荐

