android - Android - API 级别 21 中的日期
问题描述
您好,我对 Android 还是有点陌生,
目前我对本地日期(或我尝试过的任何其他日期格式)有一个大问题
LocalDate currentDate = LocalDate().now();
此行产生以下错误:
Call requires API Level 26 (current min is 21)
我完全理解这意味着什么,但我无法更改项目的 API 级别(因为我与老师签订了一份合同,我和一个合作伙伴将按照我们计划的方式完成我们的学校项目。 )
如何在 API 级别 21 中使用任何类型的日期?
摇篮:
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'
}
解决方案
将此添加到您的 build.gradle 文件中:
android {
compileOptions {
coreLibraryDesugaringEnabled true
}
}
较新版本的 Android Gradle 插件(从 4.0 开始)能够使用脱糖将新 API 反向移植到旧版本的 Android。您可以在此处阅读更多相关信息:https ://jakewharton.com/d8-library-desugaring/
请注意,您必须使用 Android Studio 的 Beta 版本才能访问这些功能:https ://developer.android.com/studio/preview
推荐阅读
- html - IPAD pro 中选择选项下拉列表的问题
- javascript - JS 多维数组和迭代
- python - python用https post上传字符串
- javascript - 如何在异步函数上进行回调?
- python - 即使条件尚未满足,程序也会停止
- java - Gson 将失败的字段解析视为 null
- firebase - Firebase 查询完成事件
- c# - 错误:拒绝访问注册表项“HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0”。由于 Tfs 挂起编辑
- javascript - Google Maps V3 中的单独折线
- python - discord.py remove_roles 不起作用