android - 本地 Android 库模块和 com.android.tools.build :gradle:3. 0.0

标签 android gradle android-gradle-plugin

我目前正在通过提供的迁移指南将我们的项目迁移到新的 gradle 插件 (3.0.0):

https://developer.android.com/studio/preview/features/new-android-plugin-migration.html

在我们的 Android 项目中,我们有一个库模块和 2 个应用程序模块。就目前而言,库模块没有风格,只有调试和发布构建类型,而应用程序有多种风格和构建类型。

我发现库模块的构建类型必须完全匹配应用模块的构建类型。例如,

如果应用模块有一个名为 debugProguard 的构建类型,那么库模块也必须有一个名为 debugProguard 的构建类型。这意味着在库模块中我最终不得不声明没有主体的 buildTypes:

    buildTypes {
        ...

        debugProguard {
        }

        ...
    }

(从这里开始: Android Studio 3.0 Error. Migrate dependency configurations for local modules )

有没有办法避免这种情况?图书馆需要了解消费应用程序的架构,这似乎很奇怪。

理想情况下,我想做的是告诉构建系统将库的特定构建类型用于应用程序的构建类型。例如,对于应用程序中的构建类型 x、y、z,在库中使用“debug”,对于 i、j、k 使用“release”。

提前致谢

最佳答案

他们刚刚在 Canary 7 中解决了这个问题Android Studio 3.0 发布:

You can now specify an alternative build type the consumer should use from the producer using the android.buildTypeMatching property as shown below. The plugin uses the alternative build type only if a matching build type is not found.

android {
    …
    // Let's say your app configures a 'staging' build type and a library module
    // it depends on does not. You can use the property below to tell the Android plugin
    // to use a library's 'debug' build type instead.
    buildTypeMatching 'staging', 'debug'
}

关于android - 本地 Android 库模块和 com.android.tools.build :gradle:3. 0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45011953/

相关文章:

gradle - 通过 Gradle 和 Android NDK 强制 CMake 处于详细模式

android - 为什么在 Android Studio 中会出现 "Failed to resolve"错误?

android - 删除图像 ListView 中不必要的空格

grails - 使用build.gradle文件将项目从2.4.3转换为3.0.X?

java - 在 gridview 中显示 ArrayList 中的值并更改文本大小

java - 类路径或引导类路径中的 Gradle + Retrolambda : Fatal Error: Unable to find package java. lang

安卓|无法添加版本 15.0.1 的所有 Google 库

java - 缺少Gradle文件的Android Studio同步项目

android - 状态栏和导航栏上的 Google Now 渐变/阴影

Android:Eclipse 保留 Build Workspace,无限循环