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?
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
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View