使用 okhttp-3.12.0 Android 找不到类"kotlin.text.Charsets"错误



代码没有任何问题,所以我只是复制错误。我正在使用okhttp 3.12.0从互联网上获得一些东西(在Android编程中(

下一行可能是主要问题:

java.lang.ClassNotFoundException: Didn't find class "kotlin.text.Charsets"

AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
   Process: com.example.infitualer.ipdemo, PID: 3306
   java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:325)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)
    Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/text/Charsets;
       at okio.Buffer.<clinit>(Buffer.kt:2212)
       at okhttp3.ResponseBody.create(ResponseBody.java:210)
       at okhttp3.internal.Util.<clinit>(Util.java:62)
       at okhttp3.internal.Util.immutableList(Util.java:0)
       at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:127)
       at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:34)
       at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:25)
       at android.os.AsyncTask$2.call(AsyncTask.java:305)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
       at java.lang.Thread.run(Thread.java:761) 
    Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.text.Charsets" on path: DexPathList[[zip file "/data/app/com.example.infitualer.ipdemo-1/base.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.infitualer.ipdemo-1/lib/x86, /system/lib, /vendor/lib]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
       at okio.Buffer.<clinit>(Buffer.kt:2212) 
       at okhttp3.ResponseBody.create(ResponseBody.java:210) 
       at okhttp3.internal.Util.<clinit>(Util.java:62) 
       at okhttp3.internal.Util.immutableList(Util.java:0) 
       at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:127) 
       at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:34) 
       at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:25) 
       at android.os.AsyncTask$2.call(AsyncTask.java:305) 
       at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
       at java.lang.Thread.run(Thread.java:761) 

您必须为Okio使用Kotlin stdlib依赖项。要么使用OkHttp所依赖的Okio 1.1.15,要么包括Okio 2.0所依赖的Kotlin stdlib。

从MvnRepository下载Okio 1.1.15.jar并将其添加到lib文件夹中,然后配置依赖

implementation files('libs/okio-1_15_0.jar')

相关内容

  • 没有找到相关文章

最新更新