Android: AbstractMethodError for Function+lambda when proguard is used
See original GitHub issueThere is some mess with proguard optimizations for android when Function is instantiated with lambda
com.google.common.base.Function<String, String> function = (u) -> u + "+1";
String s1 = function.apply("aaaa");
gives me
Process: by.stari4ek.tvirl.debug, PID: 21741
java.lang.AbstractMethodError: abstract method "java.lang.Object com.google.common.base.Function.a(java.lang.Object)"
But changing it to
Function<String, String> function = new Function<String, String>() {
@Override
public String apply(@NonNull String input) {
return input + "+1";
}
};
String s1 = function.apply("aaaa");
works well
Proguard, mapping
-keepnames class com.google.common.**
com.google.common.base.Function -> com.google.common.base.Function:
java.lang.Object apply(java.lang.Object) -> a
boolean equals(java.lang.Object) -> equals
build.gradle
buildToolsVersion = '28.0.1'
compileSdkVersion = 27
minSdkVersion = 21
targetSdkVersion = 27
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//
api 'com.google.guava:guava:26.0-android'
Devices
Reproduced on NVidia Shield (API 26) and Emulator (API 27)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
java.lang.AbstractMethodError: abstract method "void retrofit2 ...
In this class I use retrofit2 to connect http API with enqueue mode. Now, what makes me crazy is that, in Debug buildType,...
Read more >AbstractMethodError when calling interface provided as Java ...
AbstractMethodError at runtime after updating to Android Gradle Plugin 3.4.1 ... proguard notifies me that there are missing classes that are referenced
Read more >729 Obfuscation of closure method causes AbstractMethodError
Checkout the following commit from my project. Install the release version via ./gradlew installFlossRelease; Open the app and add a widget to ...
Read more >AbstractMethodError - Android Developers
AbstractMethodError(). Constructs an AbstractMethodError with no detail message. AbstractMethodError(String s). Constructs an AbstractMethodError with the ...
Read more >ProGuard Troubleshooting
For proper processing, all libraries that are referenced by your code must be specified, including the Java run-time library. For specifying libraries, use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I fixed this one with:
This is needed because Proguard has some difficulty to manage obfuscating/renaming method name and keeping lambda functionality. I said “has some difficulty” because this error doesn’t appear always, but only in certain cases.
I’m going to close this - if you gain any new information feel free to comment here and we’ll revisit.