chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
763 stars 130 forks source link

Java 8 interface `default` and `static` methods can't be called from Python on Android when minSdk < 24 #1204

Open mhsmith opened 2 weeks ago

mhsmith commented 2 weeks ago

For default methods, "desugaring" occurs to transform the bytecode into something which could have been generated by a Java 7 compiler. Based on my experiments, desugaring always occurs unless one of the following is true:

Based on my experiements with dexdump, the desugaring works as follows:

So at runtime, the reflection API will indicate that the methods are abstract and not default. They can still be called via the subclass, but they can't be called via the interface. And the extra abstract methods may prevent the interface from being recognized as functional (which is why test_call_interface_default is disabled on Android).

The only workaround I can see is to detect the existence of the $-CC class, and use it to work out which methods are supposed to be default.

mhsmith commented 2 weeks ago

No users have complained about this, and increasing minSdk is an easy workaround. So we can probably just leave this issue open for visibility until our minimum API level is 24 or higher, at which time it can be closed.

However, there may be some non-Android-specific corner cases that we still don't cover (#1205).