Demand background:
In daily development, we often use gradle for project construction. There are two modules in an app project, where A is an application module and B is a library module. Colleague A compiles and depends on B, and both have debug and release versions. I would like to ask: If the unification of A and the compiled version is realized, that is, compiling the debug version of A also compiles the debug version of B, and compiling the release version of A also compiles the release version of B.
The realization effect diagram is as follows:
Implementation:
1. Add all dependent libraries to build.gradle
android {
publishNonDefault true //表示该Module不使用默认配置
}
In the above figure, the application depends on 3, then add this sentence in the build.gradle of the 3 modules.
2. In the build.gradle of the application module, add all its dependent libraries as follows:
dependencies {
releaseCompile project(path: ':library', configuration: 'release')
debugCompile project(path: ':library', configuration: 'debug')
}
According to the example in the above figure, add in the application module
dependencies {
releaseCompile project(path: ':lib-zxing', configuration: 'release')
debugCompile project(path: ':lib-zxing', configuration: 'debug')
releaseCompile project(path: ':supertoasts', configuration: 'release')
debugCompile project(path: ':supertoasts', configuration: 'debug')
releaseCompile project(path: ':material-calendarview-library', configuration: 'release')
debugCompile project(path: ':material-calendarview-library', configuration: 'debug')
}
3. Rebuild gradle to achieve the above requirements.