Reputation: 512
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 ?
Upvotes: 7
Views: 5668
Reputation: 1468
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.
Upvotes: 11
Reputation: 9814
If I understand correctly you have a debug directory. Put the classes that are different in there. The same classes should be in the release directory (create this directory). These classes can not be in the main directory! The main directory will now be the shared code set. In a debug build it will get the classes from the debug directory and in release mode it will get the classes from the release directory. If you need any help adding the release directory let me know.
Upvotes: 9