Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

java.net.http package can't be resolved in android kotlin project

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PS: I’ve read this answer before I post but unfortuntely it did not help, as I said in the post "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", and entries in my build.gradle are all set to jdk version 11. I don’t know if there’s something I missed.

>Solution :

(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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading