我目前正在通过提供的迁移指南将我们的项目迁移到新的 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/