nostr-java icon indicating copy to clipboard operation
nostr-java copied to clipboard

java.net.http.HttpClient not compatible with Android

Open kuiperanon opened this issue 1 year ago • 3 comments

I'm getting this when the library running on Android attempts to connect:

05-11 16:31:08.623 E/AndroidRuntime(21464): java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/net/http/HttpClient;

Full error output: https://gist.github.com/kuiperanon/b20ac52ff97e3cda52c44ceb94a10b29

I think we could make ConnectionImpl.java into a service that could replaced using different providers, and then one provider could be compatible with Android. Or should we just find a solution that is compatible with everything?

kuiperanon avatar May 11 '24 21:05 kuiperanon

I'll post a PR where I replace java.net.http with OKHttp and see what you think @tcheeric

kuiperanon avatar May 12 '24 16:05 kuiperanon

Great. Send your PR against the 0.6.1-SNAPSHOT branch.

tcheeric avatar May 12 '24 16:05 tcheeric

I think the OkHttp library might be limited to only work with urls with the http or https scheme.

https://square.github.io/okhttp/5.x/okhttp/okhttp3/-ok-http-client/new-web-socket.html

https://square.github.io/okhttp/5.x/okhttp/okhttp3/-request/index.html

https://square.github.io/okhttp/5.x/okhttp/okhttp3/-http-url/index.html

HttpUrl:

this class only supports http and https

EDIT: Nevermind, I found out that I can just replace wss with https, etc.

kuiperanon avatar May 13 '24 21:05 kuiperanon

Here's my current draft of the PR. https://github.com/tcheeric/nostr-java/pull/166

kuiperanon avatar May 25 '24 14:05 kuiperanon

I shouldn't have closed this until this is done and merged: https://github.com/tcheeric/nostr-java/pull/168

kuiperanon avatar May 27 '24 21:05 kuiperanon