Android - API Level 21中的日期

4

你好,我对安卓还不太熟悉,

目前我遇到了一个关于本地日期(或者任何其他我尝试过的日期格式)的大问题。

LocalDate currentDate = LocalDate().now();

这行代码产生了以下错误:

Call requires API Level 26 (current min is 21)

我完全理解这意味着什么,但是我无法更改项目的API级别(因为我和我的伙伴与老师签署了合同,要按照我们计划的方式完成学校项目)。

我如何在API Level 21中使用任何类型的日期?

Gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.fragment"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "0.5"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
    android {
        compileOptions {
            coreLibraryDesugaringEnabled true
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-database:19.2.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.firebase:firebase-client-android:2.5.2'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'me.dm7.barcodescanner:zxing:1.9'
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:22.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'

}

或者这个,或者这个,或者这个 - Ole V.V.
1个回答

20

我在一个团队中与其他人一起工作,他们每个人现在都需要这个测试版吗? - CodeChris B
1
我相信是的。另一个选择是使用流行的ThreeTenABP库。虽然它不是Java 8版本的库,但API基本上完全相同。 - Ben P.
1
谢谢,我已将此标记为正确答案。我想我会尝试使用ThreeTenABP,因为如果我告诉团队中的其他人他们必须安装不同版本的话,他们可能会杀了我。谢谢Ben P。 - CodeChris B

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接