can't find enclosing method 'void lambda$getTestFlowable$0(io.reactivex.FlowableEmitter)'

1.2k views Asked by At

I use RxJava2 and Retrolambda in my project and for some time I felt very good, wrapping callbacks into flowables, but one day I've faced this error and if I try to run proguard on this very simplified code snippet:

    private Flowable<Object> getTestFlowable() {
        return Flowable.create(emitter -> new Thread(new Runnable() {
            @Override
            public void run() {
                emitter.onNext("one");
                emitter.onComplete();
            }
        }).run(), BackpressureStrategy.BUFFER);
    }

Then I will get this warning, which fails my build: Warning: com.yandex.testfield.MainActivity$1: can't find enclosing method 'void lambda$getTestFlowable$0(io.reactivex.FlowableEmitter)' in program class com.yandex.testfield.MainActivity

For now, I see two temporary solutions for this problem:

  1. Do not use lambda and use anonymous class instead

    private Flowable<Object> getTestFlowable() {
        return Flowable.create(new FlowableOnSubscribe<Object>() {
            @Override
            public void subscribe(FlowableEmitter<Object> emitter) throws Exception {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        emitter.onNext("one");
                        emitter.onComplete();
                    }
                }).run();
             }
        }, BackpressureStrategy.BUFFER);
    }
    
  2. Disable proguard on the class, which contains method listed above

But I am still wondering why this happens? Is this a bug in RxJava2\Retrolambda\Proguard?

1

There are 1 answers

0
vrfloppa On

Yep, it was bug in retrolambda https://github.com/orfjackal/retrolambda/issues/121

It was fixed in 2.5.1, which was merged into gradle-retrolambda 3.6.1

This bug vanishes after updating to 3.6.1