0

I have some big chunks of code which test the behaviour of some incompletely documented Android APis (sigh) which seem to behave differently for different Android versions and I want to switch them in and out of debug builds (they are always removed from release builds) which I try to do using buildConfigFields in build.gradle like this

buildTypes {
    release {
        minifyEnabled true
        buildConfigField("boolean", "RINGERMODETEST", "false")
        ...
    }
    debug {
        // set this to false to remove the optional code
        buildConfigField("boolean", "RINGERMODETEST", "true")
        ...
    }
}

Then in my code I have

    if (BuildConfig.RINGERMODETEST) {
        // optional code
    }

To get the optional code removed I need to turn on the optimiser, but setting minifyEnabled would turn on obfuscation as well which I don't want in a debug build. There is an earlier answer to this question for Proguard at Proguard shrinking and optimizing without obfuscation, but there doesn't seem to be any documentation which says how to do it for R8. I really don't want to have to learn how to construct a complete proguard control file when it's supposed to be superseded by R8. and useProguard will apparently soon be deprecated.

  • It looks like similar question was asked [here](https://stackoverflow.com/q/51860843) and answered [here](https://www.reddit.com/r/androiddev/comments/bae6ny/r8_and_proguard/). – Alex Lipov Apr 06 '20 at 19:59
  • The answer referred to by Alex Lipov was to use Proguard, but as I said in my post, Proguard is now deprecated, so that isn't a solution which will continue to work. If R8 is supposed to replace ProGuard, it needs to be as configurable as ProGuard. – user3791713 Apr 07 '20 at 20:11
  • Actually the solution I suggested is for R8. Note that R8 takes proguard configuration files as input, which might be confusing. – Alex Lipov Apr 07 '20 at 20:19
  • The solution in @AlexLipov's answer doesn't work in R8. It still obfuscates. Here is a bit of output from my logger `D/Y0() line 845 called from p line 729 called from makeView line 116:` Y0 and p are obfuscated, not the actual method names – user3791713 Jul 08 '20 at 19:42

0 Answers0