简体   繁体   English

没有 static 方法 ThreadLocal.withInitial():commons-io 依赖

[英]No static method ThreadLocal.withInitial() : commons-io dependency

I am using commons-io dependency in my Android Studio project.我在我的 Android Studio 项目中使用 commons-io 依赖项。

implementation 'commons-io:commons-io:2.11.0'

But I am seeing these weird crashes in Crashlytics.但我在 Crashlytics 中看到了这些奇怪的崩溃。 These crashes are showing up on Android 7 and below.这些崩溃出现在 Android 7 及更低版本上。

Fatal Exception: java.lang.NoSuchMethodError: No static method withInitial(Ljava/util/function/Supplier;)Ljava/lang/ThreadLocal; in class Ljava/lang/ThreadLocal; or its super classes (declaration of 'java.lang.ThreadLocal' appears in /system/framework/core-oj.jar)
   at org.apache.commons.io.IOUtils.<clinit>(IOUtils.java:183)
   at org.apache.commons.io.IOUtils.closeQuietly(IOUtils.java:534)

I have also included Java 8 compatibility in my project.我还在我的项目中包含了 Java 8 兼容性。

android {

...
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
        jvmTarget = "1.8"
    }
}

Internally commons-io is using ThreadLocal#withInitial API which is not part of desugared library , hence the method is not available on API levels lower than 26 (Android OREO)内部 commons-io 正在使用 ThreadLocal#withInitial API 这不是 脱糖库的一部分,因此该方法不适用于 API 级别低于 26 (Android OREO)

To read more about this you can read the discussion of this thread on google issue tracker.要了解有关此内容的更多信息,您可以在 google issue tracker 上阅读此线程的讨论。

Solution:解决方案:

We can use the previous versions of commons-io which are not using the ThreadLocal API.我们可以使用未使用 ThreadLocal API 的以前版本的 commons-io。 So i ended up using implementation 'commons-io:commons-io:2.5'所以我最终使用了implementation 'commons-io:commons-io:2.5'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM