Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a set of class and resource only in debug mode with 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).

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).

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

like image 392
Jacques Giraudel Avatar asked May 25 '15 16:05

Jacques Giraudel


1 Answers

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.

like image 156
MikeWallaceDev Avatar answered Nov 15 '22 04:11

MikeWallaceDev