基于Android中摇篮多味库多味的应用程序 [英] Multi flavor app based on multi flavor library in Android Gradle

查看:1081
本文介绍了基于Android中摇篮多味库多味的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有几种口味在应用内计费系统的几个市场。

My app has several flavors for several markets in-app-billing systems.

我有这股基$ C $下我所有的项目,单个库中。所以我决定这些支付系统添加到该库产品的口味。

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.

现在的问题是可以的android库有产品的口味?

The question is can android library have product flavors?

如果是这样,我怎么能包括在应用程序的各个风味不同的味道?

If so, how can I include different flavors in respective flavor of the app?

我搜索了很多,我没有找到有关此方案的任何事情。唯一接近事情,我发现这是在<一个href="http://tools.android.com/tech-docs/new-build-system/user-guide">http://tools.android.com/tech-docs/new-build-system/user-guide:

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!

我使用的是Android的工作室0.8.2。

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:

的关键部分是设置publishNonDefault为true库build.gradle,那么所建议的用户指南,你必须定义依赖关系。

The key part is to set publishNonDefault to true in library build.gradle, Then you must define dependencies as suggested by user guide.

整个项目会是这样的:

库build.gradle:

apply plugin: 'com.android.library'

android {        
    ....
    publishNonDefault true
    productFlavors {
        market1 {}
        market2 {}
    }
}

项目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.

如果您有一个基于Android的库Studio会抱怨变量选择冲突多个应用模块,它的确定,只是忽略它。

If you have multiple app module based on the library Android Studio will complain about Variant selection conflict, It's ok, just ignore it.

这篇关于基于Android中摇篮多味库多味的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆