I'm working on an simple android kotlin project which use the build-in java.net.http.HttpClient to make http post request, but it always failed to build, the error is:
Unresolved reference: http
Unresolved reference: HttpClient
Unresolved reference: HttpRequest
Unresolved reference: HttpResponse
settings in build.gradle
:
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
The gradle JDK location and my JAVA_HOME
variable point to the same environment which is the build-in version 11.0.3 under my-android-studio-path/jre
PS: I've read this answer before I post but unfortuntely it did not help, I don't know if there's something I missed.
(Sources: How can I use JDK 11 HTTP packages in Android, Using Java 11 libraries on Android Kotlin projects)
increasing the language level is of no use in this case as the used classes like java.net.http.HttpClient are simply not available on Android