在 Android Studio 和 Gradle 中的 Android App Module 中使用不同构建类型的 Library Module [英] Use different build types of Library Module in Android App Module in Android Studio and Gradle

查看:24
本文介绍了在 Android Studio 和 Gradle 中的 Android App Module 中使用不同构建类型的 Library Module的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作区,其中包含多个不同的应用程序和一个通用库项目,我希望将其从 Eclipse 转换为 Android Studio,并从 Ant 转换为 Gradle.目前,在我们的 ant 脚本中,我们在编译之前替换了一些类中的文本,具体取决于构建是用于调试目的、QA、Beta/客户验收测试还是打算发布到 Google Play.

I have a workspace containing several different apps and a common library project that I am looking to convert from Eclipse to Android Studio and from Ant to Gradle. Currently, in our ant scripts we replace text in a few of our classes before compiling depending on if the build is for debug purposes, QA, Beta/Customer Acceptance testing or meant for release to Google Play.

我想利用 Gradle 中的构建变体系统并使用值资源(布尔值、字符串等)来避免构建脚本替换我的类中的文本.

I want to take advantage of the build variant system in Gradle and use value resources (booleans, strings, etc) to keep from having the build script replace text in my classes.

由于在我的所有应用程序产品中为所有构建类型复制不同的值将是一个维护难题,因此我想将它们放在我的公共库中的构建类型中.我试过了,但无论我在应用模块中使用哪种构建类型,应用模块都会引入公共库模块的发布版本.

Since duplicating the different values for all of the build types in all of my app products would be a maintenance headache, I want to put them in the build types in my common library. I tried this but no matter which build type I use in my app modules, the app module pulls in the Release build of the common library module.

有什么办法可以让应用模块的不同构建类型使用库模块的相应构建类型吗?

Is there any way that I can get the different build types of the app modules to use the corresponding build type of the library module?

这是从 Android Studio 运行的,构建变体工具窗口显示两个模块都使用调试变体.图像应为应用程序和库读取调试.

This was run from Android Studio with the Build Variants tool window showing both modules as using the debug variant. The image should read debug for both app and library.

推荐答案

好吧,Gradle Android 插件根本无法构建依赖库模块的调试version.这是一个众所周知的老问题,这不是还没解决.
您可以尝试使用我提到的讨论中的一些解决方法,特别是查看帖子 #35 和 #38.

Well, Gradle Android plugin simply can't build the debug version of dependent library modules. This is a well-known, old issue and this is not resolved yet.
You can try to use some workarounds from the discussion I mentioned, specifically take a look at posts #35 and #38.

这篇关于在 Android Studio 和 Gradle 中的 Android App Module 中使用不同构建类型的 Library Module的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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