0

Seen questions like this. While it is possible to exclude certain files based on product flavours is it possible based on build variant?

I have some debug Dependencies and hence the release build variant does not compile.

Thanks!

If you are wondering why I am even trying this : Exclude class from kotlin compile path for release build type

Arka Prava Basu
  • 2,366
  • 3
  • 18
  • 34
  • [exclude is not supported](https://stackoverflow.com/questions/54376686/how-to-exclude-kotlin-files-from-compiling-with-gradle) – Alex Cohn Sep 24 '20 at 08:18

2 Answers2

2

If your file differs among variants then have them different per variant instead of excluding them. This makes things more clear. Your debug dependencies would then be only in debug variant which is what all this is exactly for. note that depending on your code structure you may need to provide dummy files (i. e. empty classes, or no-op implementation to satisfy interface etc).

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • This is what I am trying : https://stackoverflow.com/questions/56068365/exclude-class-from-kotlin-compile-path-for-release-build-type – Arka Prava Basu May 16 '19 at 07:15
2

In Android you rather include conditionally than excluding certain files.

You just need to use the source set for debug and put your classes in there.

Now these sources are not used for release. But it might be necessary to have some dummy implementations with no-op implementations for release to satisfy the compiler in the end.

tynn
  • 38,113
  • 8
  • 108
  • 143
  • Thanks! I went with this approach in the end. I was using `buildConfigField` to provide implementation for an interface based on `release` or `debug`. Hence wanted that exclude logic to be in the same `build.gradle` too. Your solution removes both of it :) – Arka Prava Basu May 16 '19 at 15:52