Created a new android project then I have added a new module to it. The idea is to separate all my network calls and serialization to a separate module.
module was created by right click on project > new > module > Java or Kotlin Library. This added a new module, but all the extensions functions that work on Strings show error:
Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.String'. Check your module classpath for missing or conflicting dependencies
my new module build.gradle is:
plugins {
id 'java-library'
id 'kotlin'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.31'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.2")
testImplementation 'junit:junit:4.13.2'
}
and a single class, which has errors:
package com.example.lib
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
class MyClass {
private val client = OkHttpClient()
fun makeRequest() {
val randomVariable = "lowercase letters".uppercase()
val request = Request.Builder()
.get()
.url("https://stackoverflow.com/")
.build()
val response = client.newCall(request).execute().body?.string()!!
}
}
I have tried to invalidate cache, clean .gradle cache, reboot, used Java 8 and Java 11 for Gradle JDK but did not work...
