在产品风味的Andr​​oid摇篮资源库 [英] Android gradle library resources in product flavor

查看:181
本文介绍了在产品风味的Andr​​oid摇篮资源库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已更新至1.12摇篮,摇篮插件机器人工作室0.10。

Updated to gradle 1.12, gradle plugin for android studio 0.10.

我的项目结构如下:

  • 3rdParty文件

  • 3rdparty

  • 图形
    • 图标集
      • IconsetBase (Android的库)
      • Iconset1 (Android的库)
      • Iconset2 (Android的库)
      • Graphics
        • Iconsets
          • IconsetBase (android-library)
          • Iconset1 (android-library)
          • Iconset2 (android-library)

          MainProject

          MainProject

          • 在SRC
            • 主要(主体工程)
            • flavor1
            • flavor2
            • ...
            • src
              • main (main project)
              • flavor1
              • flavor2
              • ...

              如何获得IconsetBase + Iconset1的资源文件夹的内容将合并到flavor1和IconsetBase + Iconset2到flavor2?

              How to get the res folder contents of IconsetBase + Iconset1 to be merged into flavor1 and IconsetBase + Iconset2 into flavor2?

              在升级到新的摇篮这一工作作为库(IconsetBase,Iconset1和Iconset2)有相同的包名称主要

              Before upgrading to new gradle this worked as the libraries (IconsetBase, Iconset1 and Iconset2) had the same package name as main

              下面是我在项目build.gradle:

              Here is my build.gradle of the main project:

              buildscript {
                  repositories {
                      mavenCentral()
                  }
                  dependencies {
                      repositories {
                          mavenCentral()
                      }
                      classpath 'com.android.tools.build:gradle:0.10.0'
                  }
              }
              
              apply plugin: 'android'
              
              repositories {
                  mavenCentral()
              }
              
              android {
                  useOldManifestMerger false
                  compileSdkVersion 19
                  buildToolsVersion "19.0.3"
              
                  lintOptions {
                     ...
                  } 
              
              sourceSets {
                  main.java.srcDirs = ['src/main/java']
                  main.resources.srcDirs = ['src/main/res']
              }
              
              signingConfigs {
                  ...
              }
              
              buildTypes {
                  ...
              }
              
              // Common dependencies
              dependencies {
                 compile project(':3rdparty:Graphics:Iconsets:IconsetBase')
              }
              
              defaultConfig {
                  ...
              }
              
              productFlavors {
                  flavor1         { packageName "..."}
                  flavor2         { packageName "..."}
              }
              
              android.sourceSets.flavor1 {
                  dependencies { compile project(':3rdparty:Graphics:Iconsets:Iconset1') }
                  res { srcDir 'flavor1' }
                  resources { srcDir 'flavor1' }
              }
              android.sourceSets.flavor2 {
                  dependencies { compile project(':3rdparty:Graphics:Iconsets:Iconset2') }
                  res { srcDir 'flavor2' }
                  resources { srcDir 'flavor2' }
              }
              }
              
              dependencies {
                  compile 'com.android.support:support-v4:19.1.0'
                  compile 'com.android.support:appcompat-v7:19.1.0'
                  compile 'com.google.android.gms:play-services:4.3.23'
              }
              

              =编辑=

              =EDIT=

              进一步说明:

              我追求的是合并从其他位置动态资源。

              What I seek is to merge resources from another location dynamically.

              背景:flavor1有设定图像ICON1和图标2基地的图标,flavor2有基地图标集和ICON1和图标2还,但图标是每个图标集不同。否则,我就必须有ICON1,图标2等每味多次,并在更新/这些图标的变化必须为每一种滋味现有的做(我有超过20个)

              Background: flavor1 has base icon set with images icon1 and icon2, flavor2 has base iconset and icon1 and icon2 also, but the icons are different per icon set. Otherwise I would have to have icon1, icon2 etc. per flavor many times, and on updates /changes of those icons It must be done for every flavor existing (I have more than 20)

              难道这是一些自定义任务,实现了无库?

              Could this be achieved with some custom task without libraries?

              推荐答案

              您可以通过味道定义一个特定的依赖关系:

              You can define a specific dependency by flavor :

              productFlavors {
                  flavor1 {
                     ...
                     dependencies {
                       flavor1Compile project(':iconSet1')
                     }
                  }
                  flavor2 {
                     ...
                     dependencies {
                       flavor2Compile project(':iconSet2')
                     }
                  }
               }
              

              在您构建的依赖都在SourceSets,这就是错误的。

              In your build the dependencies are in the SourceSets and that's wrong.

              修改

              好吧,我希望我更好地了解你现在的目标。你可以做的就是定义每个味道多个资源目录:

              Ok, I hope I better understand your goal now. What you can do is defining multiple resource directory for each flavor :

              android {
                  sourceSets {
                      flavor1 {
                          res.srcDirs = ['flavor1','../3rdparty/Graphics/Iconsets/Iconset1/res']
                      }
                      flavor2 {
                          res.srcDirs = ['flavor2','../3rdparty/Graphics/Iconsets/Iconset2/res']
                      }
                  }
              
              }
              

              这篇关于在产品风味的Andr​​oid摇篮资源库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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