在androidstudio4.0.0java8+;通过desugaring提供的API不起作用
我下载了AndroidStudio 4,并根据我们的应用程序设置,尝试使用Java8的流等进行测试。我们的Sdk版本是17。我根据这个和更新了build.gradle。 但是我没有访问Java8的功能,比如Stream、StreamSupport或Collections.Stream()。 我想知道我在这里错过了什么。 我已经用Android Studio模板创建了一个基本项目。项目的构建梯度如下所示:在androidstudio4.0.0java8+;通过desugaring提供的API不起作用,android,android-studio,gradle,java-8,android-gradle-plugin,Android,Android Studio,Gradle,Java 8,Android Gradle Plugin,我下载了AndroidStudio 4,并根据我们的应用程序设置,尝试使用Java8的流等进行测试。我们的Sdk版本是17。我根据这个和更新了build.gradle。 但是我没有访问Java8的功能,比如Stream、StreamSupport或Collections.Stream()。 我想知道我在这里错过了什么。 我已经用Android Studio模板创建了一个基本项目。项目的构建梯度如下所示: // Top-level build file where you can add conf
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
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
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 17
targetSdkVersion 17
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.5'
}
模块build.gradle
如下所示:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
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
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 17
targetSdkVersion 17
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.5'
}
这是gradle.properties
:
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048m
android.enableJetifier=true
我希望您需要的
compileSdkVersion
远远高于17
。是的,在添加compileSdkVersion时它可以工作。如果你把它作为答案写下来,我会接受它作为答案。但这并不能解决我们的问题。我们在Android平台17中使用SerialManager和SerialPort类,当我编写编译器DKVersion 29时,它下载新平台,但找不到SerialPort和SerialManager“如果您将其作为答案编写,我将接受其作为答案”-我建议您回答自己的问题,正如您所知,您对Gradle设置所做的更改解决了这个问题。“我们在Android平台17中使用SerialManager和SerialPort类”——您确定您使用的是正式的Android SDK吗?基于@commonware,这些类一直是隐藏的,你是对的。我们正在使用一家公司为他们自己的董事会开发的安卓系统的改进版。我希望我们在开发时可以使用Java8的特性,除了使用反射来处理这些类之外,我怀疑你运气不好。