26

I use Android Studio 3.3 Canary 5, Gradle 4.9, gradle plugin 3.3.0-alpha05

minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Does't work.


Edit:

@JakeWharton: "You use ProGuard configurations for this, not a Gradle DSL. Disable shrinking with -dontshrink, disable obfuscation with -dontobfuscate, and disable optimization with -dontoptimize."

TLDL

proguard-rules.pro

-dontshrink
-dontobfuscate
-dontoptimize
norbDEV
  • 4,795
  • 2
  • 37
  • 28

3 Answers3

21

Following this answer, I was able to solve this issue. Instead of editing the build.gradle file, I added -dontobfuscate to the proguard-rules.pro file. (You can configure a different proguard rules file for debug and release builds.) This skipped the obfuscation step and allowed me to make shrink'd debug builds with R8.

eli
  • 645
  • 7
  • 15
  • 3
    From the link: @JakeWharton: "You use ProGuard configurations for this, not a Gradle DSL. Disable shrinking with -dontshrink, disable obfuscation with -dontobfuscate, and disable optimization with -dontoptimize." – norbDEV May 23 '19 at 18:40
  • We shouldn't use **gradle.properties** for this? – IgorGanapolsky Sep 24 '20 at 14:18
17

In your gradle.properties file, add this line

 android.enableR8=false

This worked for me.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Bharath
  • 391
  • 2
  • 9
0

build.gradle

buildTypes {
    release {
        shrinkResources false
        minifyEnabled true // R8 or ProGuard will be enabled.
        proguardFiles 'proguard-rules.pro'
    }
    debug {
        shrinkResources false
        minifyEnabled false // R8 or ProGuard will be disabled.
    }
}

This answer does not demonstrate how to disable obfuscation within R8. It instead shows how to disable obfuscation at the build level.

I found setting minifyEnabled to false in build.gradle disables R8 and thus removes obfuscation. Obligatory reminder: Be cautious disabling obfuscation as it will mean the source will not be cloaked whatsoever.

tyirvine
  • 1,861
  • 1
  • 19
  • 29
  • This not answer the question "How to turn off *only* the obfuscation in Android R8?" Seems to me an AI nonsense comment – norbDEV Jul 25 '23 at 12:04
  • @norbDEV This isn't an AI generated answer. I came across this question when trying to figure out how to disable obfuscation. However, I understand that my answer isn't directly related to the question so I'll edit it to reflect that. – tyirvine Jul 25 '23 at 16:15