具有多种构建类型的 Android 多种风格

标签 android gradle android-productflavors

我们有一个具有多种风格的项目,每种风格都有 3 种不同的构建类型:调试、质量检查和发布。

productFlavors {
    flavor1 {}

    flavor2 {}

    flavor3 {}   
    }

buildTypes {
    debug {
        applicationIdSuffix ".debug"
    }

    qa {
        applicationIdSuffix ".qa"

    }

    release {
   ..
    }

但对于每种风格和构建类型,我们需要不同的库依赖项。例如:

compile 'baseUrl:myLibrary:1.0.0:flavor1Release@aar'
compile 'baseUrl:myLibrary:1.0.0:flavor1Qa@aar'
...
compile 'baseUrl:myLibrary:1.0.0:flavor3Qa@aar'

我们可以使用 Groovy 脚本添加这些依赖项吗?

最佳答案

我知道您可以像这样为每个 buildType 定义特定的依赖

debugCompile 'baseUrl:myLibrary:1.0.0:debugLib@aar'
releaseCompile 'baseUrl:myLibrary:1.0.0:release:Lib@aar'
  • 编译:主应用
  • androidTestCompile:测试应用
  • debugCompile:调试构建类型
  • releaseCompile:发布构建类型。

Because it’s not possible to build an APK that does not have an associated Build Type, the APK is always configured with two (or more) configurations: compile and Compile. Creating a new Build Type automatically creates a new configuration based on its name.

它似乎也能很好地处理 flavor ,如所述here (但不使用 flavorDimensions)

为一个变体 (buildType+Flavor) 做这件事似乎需要更多的工作。否则你可以将你的库定义为一个真正的库项目并使用这样的语法

To create a dependency on another published artifact, you need to specify which one to use:

dependencies {
    flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
    flavor2Compile project(path: ':lib1', configuration: 'flavor2Release')
}

发件人:http://tools.android.com/tech-docs/new-build-system/user-guide

关于具有多种构建类型的 Android 多种风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29030840/

相关文章:

android - Gradle 将 resources.jar 和 aar 上传到 jfrog artifactory。 ArtifactoryPublish会生成两个pom-default.xml,它会随机推送其中一个

Android - 根据口味更改应用程序版本名称

android - Kotlin android 扩展,无法导入包

android - 使用改造的android中json的空指针异常

android - 我无法将 gradle 插件版本更新到 4.1.3

安卓工作室 3.4.3 : unable to resolve dependencies

Android - 单击后退时语言更改

java - 如何在 Java 中锁定线程的代码块

android - 如何在 BuildSrc 中创建 FlavorConfig?

android - 有没有办法根据选定的 productFlavor 更改 gradle 变量值?