-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jetty's use of java.util.ServiceLoader$Provider
breaks on Android (as it is not present)
#8912
Comments
We cannot fix this.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.Provider.html There many components that rely on this, and Jetty is only a small part of this reliance. Looking at the android source tree, their JDK 11 has the above class. |
Closing, this works for others on Android. |
I can't get it working any way, using JDK11 and Android SDK33. I tested for JDK 11 using this API: You can find a minimal working example here: https://github.com/zugazagoitia/jett11-android13-mpoc The The reason, as stated earlier, is clear: the My question is will this be addressed or is it a priority at all? |
@zugazagoitia did you open an issue to the Android SDK to add the |
I've just commented on this issue, which seems they were considering. |
java.util.ServiceLoader$Provider
breaks on Android (as it is not present)
Update: They implemented the rest of the |
This works for me, you can create a new Android module and make sure its build.gradle uses Java 1.8,here we temporarily call it "ponyfill".
Then create a placeholder ServiceLoader type under this module (you don’t need to actually implement it), and add the Provider interface definition inside it. Android will always load the system class first when loading a class, so it It will not use the ServiceLoader we used to place the placeholder, but when it cannot find the Provider, it will use the class we provided.
Finally, you also need to "desugar" Java in your application module
|
However, things are always full of compromises, and I found a case where Jetty called a method that didn't exist on Android. On Android's non-standard jdk, ServiceLoader has no stream() method no matter what version it is, and Google's "desugar" doesn't handle this, which is frustrating and causes crashes |
Interesting that this class and method are in desugaring library https://github.com/google/desugar_jdk_libs/tree/master/jdk11/src/java.base/share/classes/java/util |
Not sure if desugaring is also applied for the test app (I assume that WireMock is running in context of the test app). |
Since Android 15 has been released, I think this issue can be closed. @joakime @sbordet |
Thanks for the feedback! |
Jetty version(s)
Jetty 11
Java version/vendor
(use: java -version)
Dalvik
OS type/version
Android SDK 33
Description
With Javalin 4 (Jetty 9) and Android I had no problems. After migrating to Javalin 5 (Jetty 11) my server doesn't startup anymore. in JDK 11 I can find the missing class (ServiceLoader$Provider) but in android sdk I cannot (https://developer.android.com/reference/java/util/ServiceLoader). I use Java 11 and compileSdkVersion 33. I cannot find ServiceLoader$Provider in SDK of Android API 33 (when decompiled).
How to reproduce?
Run Javalin 5 / Jetty 11 on Android
The text was updated successfully, but these errors were encountered: