I am developing an android application. I have an java file that I want to use it differently in debug and release build types. I know I can have different resource files for debug and release versions. But is it possible to do the same with Java files also? How to achieve this?
1 Answer
Step #1: Put the debug edition of your Java class in src/debug/java/...
Step #2: Put the release edition of your Java class in src/release/java/...
Step #3: Ensure that you do not have a copy of this Java class in src/main/java/...
Now, a debug build will pull the Java code from the debug source set, while a release build will pull the Java code from the release source set.
7 Comments
adarsh
I did the above steps, but while trying to build the debug version, I am getting below error org.gradle.api.GradleException: No matching client found for package name 'com.agmodels.bluetooth.agmodelsfeed.debug'
CommonsWare
@adarsh: I do not recognize that error message, and I do not know what "client" it might be referring to. It is possible that some plugin that you are using is now getting confused. I recommend that you ask a separate Stack Overflow question, where your minimal reproducible example includes the entire Gradle output, as the rest of the Gradle output may give people clues as to what specifically is generating the error message.
adarsh
I have found the issue, it is because of the google-services.json file. stackoverflow.com/questions/34990479/…
Someone Somewhere
I've found I had to "Invalidate Caches / Restart" because A.S. was unable to find the new location of the file. Also, pro-tip if the /debug folder is being ignored by git: update .gitignore with the line
!/src/debugnetcyrax
@CommonsWare Your answer works, I just needed to Build -> Clean first (in case someone is having the same issue). Thanks!
|