赞
踩
问题描述:在低版本安卓(sdk<26)中是无法使用jdk8的包的
我搜索了一下论坛很多人都是随意复制的,根本无法解决问题。
比如这个,我最低sdk设置的24,同步时直接报错。
- jackOptions {
- enabled true
- }
今天(2021.9.7)我详细查看了一下文档,得到下面结果
1.将build.gradle(Project)版本设置到4.0,可以先同步下载
- buildscript {
- repositories {
- mavenLocal()
- mavenCentral()
- maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
- maven { url "https://plugins.gradle.org/m2/" }
- maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
- google()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:4.0.0'
- }
- }
2.在build.gralde(Module) 中进行细节配置 在android { } 中配置
- android{
-
- ...
- defaultConfig {
- ...
- minSdkVersion 24
- targetSdkVersion 31
- versionCode 1
- versionName "1.0"
- // 如果你的最低sdk(minSdk)是20或更低需要配置下面一行
- multiDexEnabled true
- }
- compileOptions {
- // 开启以支持新的语言特性
- coreLibraryDesugaringEnabled true
- // 设置Java为1.8版本
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- }
-
- dependencies {
- coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
3.改好以后点 sync 同步以后即可,就可以使用新版的API了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。