問題描述
我的應用針對多個市場的應用內(nèi)計費系統(tǒng)具有多種風格.
我有一個共享我所有項目的基本代碼的庫.所以我決定將這些支付系統(tǒng)作為產(chǎn)品風味添加到這個庫中.
問題是android庫可以有產(chǎn)品風味嗎?
如果是這樣,我如何在應用的各個風味中包含不同的風味?
我搜索了很多,但我找不到關(guān)于這個場景的任何信息.我發(fā)現(xiàn)的唯一接近的東西是
My app has several flavors for several markets in-app-billing systems.
I have a single library which shares the base code for all of my projects. So I decided to add those payment systems to this library as product flavors.
The question is can android library have product flavors?
If so, how can I include different flavors in respective flavor of the app?
I searched a lot, and I couldn't find anything about this scenario. The only close thing I found was this in http://tools.android.com/tech-docs/new-build-system/user-guide:
dependencies {
flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
flavor2Compile project(path: ':lib1', configuration: 'flavor2Release')
}
I changed configuration to different things but it did not work!
I'm using android studio 0.8.2.
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.
這篇關(guān)于基于 Android Gradle 中多風味庫的多風味應用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!