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

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

Open
mhsmith opened this issue Jul 6, 2024 · 1 comment
Labels

Comments

@mhsmith
Copy link
Member

mhsmith commented Jul 6, 2024

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:

  • minSdkVersion >= 24; or
  • The app is being run from Android Studio using the play button, on a device with API level >= 24, and (minSdkVersion >= 21 or multiDexEnabled).

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

  • The default methods are marked as abstract in the interface itself.
  • The compiler outputs a separate $-CC class which contains the method implementations.
  • Every subclass which doesn't override the default method will have a synthetic method generated which calls the default implementation.

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
Copy link
Member Author

mhsmith commented Jul 6, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant