【问题标题】:Local Android Library Modules and com.android.tools.build:gradle:3.0.0本地 Android 库模块和 com.android.tools.build:gradle:3.0.0
【发布时间】:2017-07-10 12:24:00
【问题描述】:

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

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

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

我发现库模块的 buildTypes 必须与应用程序模块的 buildTypes 完全匹配。例如,

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

    buildTypes {
        ...

        debugProguard {
        }

        ...
    }

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

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

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

提前致谢

【问题讨论】:

    标签: android gradle android-gradle-plugin


    【解决方案1】:

    他们刚刚在 Android Studio 3.0 的Canary 7 版本中解决了这个问题:

    您现在可以指定消费者应该使用的替代构建类型 从生产者使用 android.buildTypeMatching 属性作为 如下图所示。插件仅在以下情况下使用替代构建类型 找不到匹配的构建类型。

    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'
    }
    

    【讨论】:

    猜你喜欢
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多