Ad

How To Keep Class Constructor Argument Parameter Names With Android R8

I'm writing Android library, so I want to preserve parameter names for some constructors/methodes. I'm deploying my library as AAR file.

After Gradle upgrade from 3.3.2 to 3.4.0 all arguments in constructors and public methods are renamed to something like "var1", before that everything was fine.

As I understand main difference is that, now by default R8 is used to minify and obfuscate our code instead of Proguard. So probably I'm missing something in configuration.

Let's say that I have class:

public class Foo {
    public String bar;

    public Foo(String bar) {
        this.bar = bar;
    }
}

So in proguard-rules.pro I have:

-keepparameternames
-keepattributes MethodParameters
-keepattributes Signature

-keep class my.class.path.Foo { *; }

And I load that configuration in my module gradle file:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}}

Right now my class inside my AAR file looks like that ->

public class Foo {
    public String bar;

    public SecureElement(String var1) {
        this.bar = var1;
    }
}

So even field name has been preserved, but not variable name in my constructor.

How can I preserve method/constructor argument names?

What am I missing?

Ad

Answer

As said here, check if everything works for you with R8 version 1.5.51

buildscript {
    repositories {
        maven {
            url 'http://storage.googleapis.com/r8-releases/raw'
        }
    }
    dependencies {
        // Must be before the Gradle Plugin for Android
        classpath 'com.android.tools:r8:1.5.51'
        classpath 'com.android.tools.build:gradle:X.Y.Z'
     }
}

Or you can disable R8 as described here

You can disable R8 by adding one of the following lines to your project’s gradle.properties file:

# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false
Ad
source: stackoverflow.com
Ad