我怎么能每味buildType sourceSets指定? [英] How can I specify per flavor buildType sourceSets?

查看:540
本文介绍了我怎么能每味buildType sourceSets指定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2香精的应用程序中,每个都有自己的谷歌地图(V1)键调试和发布(这意味着4个按键总数)。所以我想知道如果我能指定的基础上buildType和productFlavor sourceSets。从本质上讲,我想知道我如何能实现这样的:

I've got 2 flavors of an app that each have their own google maps (v1) key for debug and release (meaning 4 keys total). So I'd like to know if I can specify sourceSets based on the buildType and productFlavor. Essentially, I'm wondering how I can achieve something like this:

src
├── debug
│   └── flavor1
│       └── res
│           └── values
│               └── gmaps_key.xml
├── release
│   └──flavor1
│       └── res
│           └── values
│               └── gmaps_key.xml

如果摇篮会使用的src /< currentBuldType> /< currentProductFlavor> / * 作为其sourceSet的一部分。

Where gradle will use the src/<currentBuldType>/<currentProductFlavor>/* as part of its sourceSet.

基本上我希望它这样,如果我跑摇篮assembleFlavor1Debug 将包括在一切的src /主/ * 的src / flavor1 / * 的src /调试/ flavor1 / *

Essentially I want it so that if I run gradle assembleFlavor1Debug it will include everything under src/main/*, src/flavor1/*, and src/debug/flavor1/*.

我的build.gradle是超级简单:

My build.gradle is super simple:

buildscript {
    repositories {
        mavenCentral()
    }   

    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.0'
    }   
}

apply plugin: 'android'

android {
    compileSdkVersion 8

    productFlavors {
        flavor1 {
            packageName 'com.flavor1'
        }
        flavor2 {
            packageName 'com.flavor2'
        }
    }
}

有什么想法?或者,也许更好的做法呢?

Any thoughts? Or maybe a better approach to this?

推荐答案

有关谷歌地图API的整合,你可以检查我的摇篮样品code在这里:的 https://github.com/shakalaca/learning_gradle_android/tree/master/07_tricks

For Google Maps API integration you can check my gradle sample code here : https://github.com/shakalaca/learning_gradle_android/tree/master/07_tricks

基本上做到在 mergeResources 相小动作 android.applicationVariants.all ,然后将API密钥在不同flaver / buildtype组合文件夹的strings.xml。

Basically do a little trick in android.applicationVariants.all during the mergeResources phase, and place the API key in strings.xml under different flaver/buildtype combination folder.

这篇关于我怎么能每味buildType sourceSets指定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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