链接特定口味与尺寸的依存关系 [英] Link dependencies for specific flavors with dimensions

查看:62
本文介绍了链接特定口味与尺寸的依存关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发具有两种类型的android应用:免费和高级.每层都有2个版本:轻量级和重型. 这是Gradle的实现:

I'm developing an android app which has two types: free and premium. Each tier has 2 versions: lightweight and heavy. Here's the Gradle implenetation of this:

flavorDimensions "tier", "distro"
productFlavors {
    free {
        dimension "tier"
    }
    premium {
        dimension "tier"
    }
    lightweight {
        dimension "distro"
    }
    heavy {
        dimension "distro"
    }
}

我正在尝试为高级套餐 添加一个.jar依赖项.添加它的方法很简单:

I'm trying to add a .jar dependency for the premium tier only. The way to add it is quite trivial:

premiumImplementation fileTree(dir: 'libs', include: ['*.jar']) // Works

问题是我有这个.jar的两个版本.上面提到的每个颠覆项之一:lightweightheavy.

The problem is that I have two versions of this .jar . One for each subversion mentioned above: lightweight and heavy.

我试图将简单的解决方案应用于这种类型的依赖项:

I tried to apply the trivial solution to this type of dependency:

premiumLightweightImplementation fileTree(dir: 'libs', include: ['*lightweight.jar'])
premiumHeavyImplementation fileTree(dir: 'libs', include: ['*heavy.jar'])

但是我收到了gradle错误:

But I get a gradle error:

找不到用于参数的方法premiumLightweightImplementation() [目录'libs']

Could not find method premiumLightweightImplementation() for arguments [directory 'libs']

当然,这也适用于premiumHeavyImplementation.

Of course this also applies to premiumHeavyImplementation.

我确定可以按照我的要求进行操作. 我发现了两种方法可以解决此问题:

I'm sure there's a gradle-way to do what I'm asking. I found two options to deal with this issue:

  1. 完全停止使用尺寸(错误的解决方案,我必须自己编写所有风味组合).
  2. 实现一个函数,该函数检索我正在尝试汇编的当前风味,并在目录路径中使用其返回值.例如:

  1. Stop using dimensions altogether (Bad solution, I'll have to write all the flavor-combinations myself).
  2. Implement a function which retrieves the current flavor I'm trying to assemble, and use its return value in a directory path. For example:

def组合= getCurrentFlavorCombination()
premiumImplementation fileTree(dir:"libs/$ combination",包括:['* .jar'])

def combination = getCurrentFlavorCombination()
premiumImplementation fileTree(dir: "libs/$combination", include: ['*.jar'])

这些是达到此简单要求的难看且不可靠的方法: 高级层应该链接有一个.jar-该.jar的版本取决于另一个维度-发行版.

These are ugly and unreliable ways to achive this simple requirement: The premium tier should have a .jar linked to it - the version of that .jar depends on another dimension - distro.

我并没有要求太多,但是在Gradle文档中找不到实现此目的的好方法.我只找到了将库编译为jar的方法,但是我的库中已经有jar了,我只希望适当地链接它.也许你们可以在这里帮助我.

I'm not asking for too much, but couldn't find in Gradle docs a nice way to do that. I only found ways to compile a library into jars, but mine already comes in jars, I only wish to link it appropriately. Maybe you guys can help me out here.

非常感谢您!

推荐答案

我正在通过

I was going by this section of the Android Studio manual which states that you need to declare explicitly any configurations that for flavor/build type combinations. In this case, that means you need to add the following to your build script before the dependencies {} block:

configurations {
    freeLightweightImplementation
    freeHeavyImplementation
    premiumLightweightImplementation
    premiumHeavyImplementation
}

这篇关于链接特定口味与尺寸的依存关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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