Edit: Thanks for the commenters trying to repro! It's starting to look like this is an issue with Dexguard specifically. this may be related to DexGuard integration in Android Studio 3.0.
So I'm running into an odd error when trying to pass a private constructor of an object as a method reference to a Supplier of the same type. I was able to boil it down to:
public class Test {
public static final Supplier<Test> supplier = Test::new;
private Test() {}
}
When trying to invoke Test.supplier.get()
, I get a crash and the following error:
java.lang.IllegalAccessError: Method 'void myapp.Test.()' is inaccessible to class 'myapp.Test$$Lambda$1' (declaration of 'myapp.Test$$Lambda$1' appears in /data/app/myapp-1/base.apk:classes2.dex)
Note that this only seems to happen for constructors: doing the following worked as expected.
public class Test {
public final Supplier<String> stringSupplier = this::buildString;
private String buildString() { return "hi!"; }
}
works fine when invoking new Test().stringSupplier.get()
from outside the class.
Meanwhile, using a lambda instead of a method reference also works without crashing for private constructors (() -> new Test()
instead of Test::new
)
anyone have any ideas?