gpt4 book ai didi

android - 创建了一个新模块但扩展函数显示错误 : Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.String'

转载 作者:行者123 更新时间:2023-12-05 05:53:51 24 4
gpt4 key购买 nike

创建了一个新的 android 项目,然后我向其中添加了一个新模块。我的想法是将我所有的网络调用和序列化分离到一个单独的模块中。

模块是通过右键单击项目 > 新建 > 模块 > Java 或 Kotlin 库 创建的。这添加了一个新模块,但是所有适用于字符串的扩展函数都显示错误:

无法访问作为“kotlin.String”父类(super class)型的“java.io.Serializable”。检查您的模块类路径是否存在缺失或冲突的依赖项

我的新模块 build.gradle 是:

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'
}

和一个有错误的类:

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()!!
}
}

enter image description here

我尝试过使缓存无效、清理 .gradle 缓存、重启、为 Gradle JDK 使用 Java 8 和 Java 11 但没有成功...

最佳答案

删除 ~/Library/Application Support/Google/AndroidStudioPreview20XX.X/options/jdk.table.xml 文件修复了这个问题。

这也是这个 https://issuetracker.google.com/issues/213131387 的问题

关于android - 创建了一个新模块但扩展函数显示错误 : Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.String' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69816003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com