首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DateTimeFormatter不适用于低于8的Android版本。

DateTimeFormatter不适用于低于8的Android版本。
EN

Stack Overflow用户
提问于 2019-07-25 13:31:47
回答 1查看 1.6K关注 0票数 2

我想从另一个时间字符串中减去30分钟,但是在较低版本(如0.5,0.6,0.7 (棒棒糖、Marshmallow、Naught) )上会出现此错误。

错误如下:

java.lang.NoClassDefFoundError:失败的决议: Ljava/time/format/DateTimeFormatter;

EN

回答 1

Stack Overflow用户

发布于 2022-07-18 13:39:00

通过在模块级build.gradle文件中添加这些行来解决这个问题

这是因为在api 26中添加了Java.time,所以下面的26会在app中抛出一个错误。

只需添加以下行

代码语言:javascript
运行
复制
android {

    defaultConfig {
        // Required when setting minSdkVersion to 20 or lower
        multiDexEnabled true
    }

    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}

确保multiDexEnabled真在版本和调试中都是正确的

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57203186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档