仅在带有 gradle 的调试模式下使用一组类和资源 [英] Use a set of class and resource only in debug mode with gradle

查看:32
本文介绍了仅在带有 gradle 的调试模式下使用一组类和资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在我处于调试模式构建类型(Android studio/gradle)时添加特定功能.将一组类和资源限制为调试构建类型(gradle).

I want to add a specific feature only when I am in debug mode build type (Android studio / gradle).to limit a set of class and resource to the debug build type (gradle).

我目前的解决方案是使用调试目录来存储额外的类和资源,并在代码中,当 BuildType.DEBUG 属性设置为 true 时,通过反射加载入口类.如果我们在调试中构建,则调试目录在构建期间与主目录合并.我首先认为这个目录与构建变体的工作方式相同,即 : 将覆盖同名的类(允许我拥有特定类的调试版本).似乎不可能(来自 Android Studio 的重复类错误).

My current solution is to use the debug directory to store the extra classes and resources and, in the code, to load the entry class by reflection when the BuildType.DEBUG property is set to true. The debug directory is merged with the main directory during the build if we are building in debug. I thought first that this directory will work the same as build variant ones, ie : will overwrite classes with the same name (permitting me to have a debug version of a specific class). It seems to be not possible (duplicate class error from Android Studio).

这是最干净的解决方案吗?是否可以直接使用 gradle 来做到这一点?

Is it the cleanest solution ? Is it possible to use gradle directly to do that ?

推荐答案

为了在您的调试和发布构建类型中有不同版本的同一个类,您需要在与您的调试"相同的级别创建一个发布"目录' 目录.将类放在相同的文件夹层次结构中,Android Studio 会在您构建发布类型时选取它.您的主目录树中不能有该类.

In order to have different versions the same class in your debug and release build types you need to create a 'release' directory at the same level as your 'debug' directory. Place the class in the same folder hierarchy and Android Studio will pick it up when you build the release type. You must not have the class in your main directory tree.

这篇关于仅在带有 gradle 的调试模式下使用一组类和资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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