How to keep class constructor argument parameter names with Android R8

雨燕双飞 提交于 2020-08-05 03:55:13

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/56057586/how-to-keep-class-constructor-argument-parameter-names-with-android-r8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!