Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method references are not taken into account by proguard #142

Closed
denis-itskovich opened this issue Oct 15, 2015 · 13 comments · Fixed by #246
Closed

Method references are not taken into account by proguard #142

denis-itskovich opened this issue Oct 15, 2015 · 13 comments · Fixed by #246

Comments

@denis-itskovich
Copy link
Contributor

I'm not sure whether it's an issue of retrolambda itself or gradle-retrolambda

Background

Proguard seems to shrink methods, referenced as method references. See an example below:

public class AsyncTaskBuilder<Progress, Result> {

    public interface BackgroundWorkWithProgress<_Progress, _Result> {
        _Result execute(ProgressObserver<_Progress> progressObserver);
    }

    private BackgroundWorkWithProgress<Progress, Result> work;

    public AsyncTask<Void, Progress, Result> build() {

        return new AsyncTask<Void, Progress, Result>() {
            @Override
            protected Result doInBackground(Void... voids) {
                // this reference will not be taken into account by Proguard
                return work.execute(this::publishProgress);
            }

        };
    }
}

After building, the following error is shown:

:app:proguardRelease
Warning: com.github.retrolambda_methodref_repro.AsyncTaskBuilder$1$$Lambda$1: can't find referenced method 'void publishProgress(java.lang.Object[])' in library class android.os.AsyncTask
Warning: there were 1 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Exception while processing task 
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:473)
    at proguard.ProGuard.initialize(ProGuard.java:233)
    at proguard.ProGuard.execute(ProGuard.java:98)
    at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
    at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
    at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
    at com.android.builder.tasks.Job.runTask(Job.java:48)
    at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
    at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
    at java.lang.Thread.run(Thread.java:745)

Full log is available at travis-ci

Sample android project

Simple android project (with 1 class), reproducing the issue can be found here:
https://github.com/denis-itskovich/retrolambda-method-ref-repro

Related issues

The issue seems to be related to this retrolambda issue: luontola/retrolambda#48

@luontola
Copy link

The log has some warnings about "AsyncTaskBuilder.java uses unchecked or unsafe operations." Does fixing those help?

@denis-itskovich
Copy link
Contributor Author

Fixed the warning (replaced varargs generic parameter by generic array parameter), but the issue still exists: https://travis-ci.org/denis-itskovich/retrolambda-method-ref-repro/builds/85513111

One more observation:

The issue does not reproduce if I replace method reference by lambda: this::publishProgress with progress -> publishProgress(progress). In this case the build succeeds.

@gmarizy
Copy link

gmarizy commented Nov 4, 2015

In my case, method references were causing failure even with proguard disabled, with error like:

E/AndroidRuntime: java.lang.NoClassDefFoundError: java.util.Objects

The reason was incompatibility with gradle-errorprone-plugin. Given that this plug-in play with compiler it's not that a surprise. It used to work with previous version of gradle-retrolambda though.

@konmik
Copy link

konmik commented Nov 14, 2015

Did you try using the latest retrolambda version?

dependencies {
    retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.0.6'

@denis-itskovich
Copy link
Contributor Author

Recently tried - getting the same error with 2.0.6

@tomblenz
Copy link

tomblenz commented Apr 3, 2016

I'm getting this same error with 3.3.0-beta4.

@formatBCE
Copy link

formatBCE commented May 27, 2016

Getting NoClassDefFound error on java.utils.Objects on both latest stable and 3.3.0 beta versions.
Could you please fix that?
We use lambdas in pretty big project, and it will take too much time to replace all method references to usual lambdas.

@evant
Copy link
Owner

evant commented May 27, 2016

You need to update to the latest retrolamba, see luontola/retrolambda#75

@formatBCE
Copy link

Same issue: java.lang.NoClassDefFoundError: java.util.Objects
build.gradle: classpath 'me.tatarka:gradle-retrolambda:3.2.5'

@evant
Copy link
Owner

evant commented May 27, 2016

You did

dependencies {
    retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.3.0'
}

correct?

@formatBCE
Copy link

I'm TRULY sorry...
Works! :)

@sunny-chung
Copy link

Reproducible in an Android project with
gradle-retrolambda 3.2.5 + retrolambda 2.3.0/2.4.0/2.5.0
gradle-retrolambda 3.5.0 + retrolambda 2.5.0,

apply plugin: 'me.tatarka.retrolambda' is put at the last.

This plugin was working at past time.

@ncruces ncruces mentioned this issue Apr 13, 2017
@ncruces
Copy link
Contributor

ncruces commented Apr 13, 2017

Ignoring these warnings is enough to fix it:

-dontwarn **$$Lambda$*

evant added a commit that referenced this issue Apr 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants