I'm using Android Studio Electric Eel | 2022.1.1 for a school project and I need to use an API.
In order to use the API I need to send an HTTP request to a certain URL.
I read about java 11's HttpClient
and HttpRequest
from the package java.net.http
and tried to use it but the android studio can't seem to find this package and puts the error:
error: package java.net.http does not exist import java.net.http.HttpClient;
I tried checking why it may show this error and I checked the gradle jdk version but it shows that it is version 11.
Android has a long history of not having traditional Java packages outside of the core collections and objects, let alone any Java features beyond Java 7 (java.time as one example).
Android has its own HTTP client library, as documented in the Connectivity guide, or you can opt for other libraries like Retrofit, for example.