How to turn off only the obfuscation in Android R8?
Asked Answered
P

3

28

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
Perfunctory answered 15/8, 2018 at 14:38 Comment(0)
H
23

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.

Hosier answered 20/4, 2019 at 14:5 Comment(2)
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."Perfunctory
We shouldn't use gradle.properties for this?Highfalutin
G
17

In your gradle.properties file, add this line

 android.enableR8=false

This worked for me.

Grogshop answered 19/4, 2019 at 15:53 Comment(4)
useProguard will soon be deprecated, any idea how we could fix this issue ? #57736608 without disabling R8?Pane
This isn't deprecated?Highfalutin
This turns off R8 completely, both obfuscation and shrinking.Niobous
This is now removed in Android Gradle Plugin 7.0Submediant
H
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.

Hilar answered 23/7, 2023 at 2:51 Comment(2)
This not answer the question "How to turn off only the obfuscation in Android R8?" Seems to me an AI nonsense commentPerfunctory
@Perfunctory 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.Hilar

© 2022 - 2025 — McMap. All rights reserved.