question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: AbstractMethodError for Function+lambda when proguard is used

See original GitHub issue

There 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rickytribbiacommented, Jan 23, 2019

I fixed this one with:

-keepnames class com.google.common.** { *; }

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.

0reactions
ronshapirocommented, Aug 13, 2018

I’m going to close this - if you gain any new information feel free to comment here and we’ll revisit.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found