项目模块新增加一个module 或 buildType的时候,出现如下问题:
/Users/chrisding/iCourt/Work/Android/alpha_android_2.0/alpha/build.gradle
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :alpha_provider.
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :component_architecture.
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :component_api.
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :component_ui.
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :lib_guideview.
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :lib_daemon.
Error:Unable to resolve dependency for ':alpha@release_abc/compileClasspath': Could not resolve project :lib_calendar.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :alpha_provider.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :component_architecture.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :component_api.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :component_ui.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :lib_guideview.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :lib_daemon.
Error:Unable to resolve dependency for ':alpha@release_abcUnitTest/compileClasspath': Could not resolve project :lib_calendar.
这个是3.0的新特性:module a 依赖module b, 那么b和a的 buildType必须全部一致。
module a:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
preRelease {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
module b:
buildTypes {
release {
minifyEnabled false
}
preRelease {
minifyEnabled false
}
}
后来我发现这样解决有坑:如果我项目里有多个可运行module,都依赖了library b呢?那岂不是所有的都这么写这么多,多不优雅!网上查了一下,有人也遇到了相同的问题,解决方式如下:
module b:
buildTypes {
release {
minifyEnabled false
matchingFallbacks ['release']
}
preTest {
minifyEnabled false
matchingFallbacks ['release']
}
}
这种方案,可以使library的buildType区别与被依赖的module的buildType,避免依赖类型必须一致的尴尬问题。当然fallback不能瞎写,只能写当前已有的buildType,是个数组,可以填多个。
亲测有效。