3

I have some code in my android application which I intend to keep only in debug-builds.

I am aware of this approach:

if (BuildConfig.DEBUG) { //code here } 

However, the problem is that my code relies on external dependencies which I would also like to keep in debug builds only :

debugCompile "dependency1" //this wont compile in release mode if (BuildConfig.DEBUG) { //code which references dependency1 } 

Given that there is no conditional compilation in java, are there any solutions besides commenting out blocks of code manually every time (which is obviously a huge hassle)?

EDIT: Egor pointed me in the right direction and after doing some more reasearch on "source sets" I found an answer which PRECISELY describes my situation and provides an excellent solution: https://stackoverflow.com/a/31483962/5790273

1 Answer 1

2

Put the code you only want to compile in debug mode under "src/debug/java", as described here. Gradle allows you to use multiple source sets per build type and flavor, and will only compile those that are relevant for the build configuration.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.