Finally I found out how to do this, I will explain it here for others facing same problem:
The key part is to set publishNonDefault to true in library build.gradle, Then you must define dependencies as suggested by user guide.
The whole project would be like this:
Library build.gradle:
apply plugin: 'com.android.library'
android {
....
publishNonDefault true
productFlavors {
market1 {}
market2 {}
}
}
project build.gradle:
apply plugin: 'com.android.application'
android {
....
productFlavors {
market1 {}
market2 {}
}
}
dependencies {
....
market1Compile project(path: ':lib', configuration: 'market1Release')
market2Compile project(path: ':lib', configuration: 'market2Release')
}
Now you can select the app flavor and Build Variants panel and the library will be selected accordingly and all build and run will be done based on the selected flavor.
If you have multiple app module based on the library Android Studio will complain about Variant selection conflict, It’s ok, just ignore it.
其他参考
https://stackoverflow.com/questions/24307596/how-can-i-add-flavors-in-a-module-with-android-studio
转载于:https://my.oschina.net/sfshine/blog/2870349
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/101336.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...