我尝试导入java.util.StringJoiner
,但收到了此消息
Usage of API documented as @since 1.8+ less... (⌘F1)
This inspection finds all usages of methods that have @since tag in their documentation. This may be useful when development is performed under newer SDK version as the target platform for production.
我正在使用:
java版“1.8.0_102”
Java(TM)SE运行时环境(版本1.8.0_102-b14)
Java HotSpot(TM)64位服务器VM(版本25.102-b14,混合模式)
如何解决这个问题。谢谢大家的帮助!!
答案 0 :(得分:0)
StringJoiner
。如果您的minSdkVersion
为24或更高(即,只能在Android 7.0及更高版本上运行),欢迎您使用它。如果您的minSdkVersion
低于24,请完全替换StringJoiner
的使用,或仅在运行API级别24或更高级别的设备上使用它。
您获得的具体消息是因为不仅在API Level 24中引入了此类,而且它来自Java 8.较旧的设备不支持Java 8类。
此外,Java 8功能需要Jack编译器,它目前不是默认编译器。您需要关注the instructions to enable Java 8 support in Gradle,添加jackOptions
和compileOptions
关闭:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.commonsware.myapplication"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}