android 接口默认方法吗,为什么Android Studio 3.0不支持默认和静态接口方法(why Default and static interface methods are not s...

为什么Android Studio 3.0不支持默认和静态接口方法(why Default and static interface methods are not supported by Android Studio 3.0)

为什么Android Studio 3.0不支持Java 8的[默认和静态接口方法]?

代码总是得到错误提示。

5f121d1959a237f46c2069b15bc93f70.png

build.gradle设置:

compileSdkVersion 26

buildToolsVersion "26.0.2"

defaultConfig {

applicationId "com.dreamzone.mtime"

minSdkVersion 18

targetSdkVersion 26

versionCode 1

versionName "1.0"

}

Why [Default and static interface methods] of java 8 are not supported in Android Studio 3.0?

The code always got the error hint.

5f121d1959a237f46c2069b15bc93f70.png

The build.gradle settings :

compileSdkVersion 26

buildToolsVersion "26.0.2"

defaultConfig {

applicationId "com.dreamzone.mtime"

minSdkVersion 18

targetSdkVersion 26

versionCode 1

versionName "1.0"

}

But android studio doc shows it can compatible any api level. https://developer.android.com/studio/write/java8-support.html cc612c4f6c87b4f129b984d0de749207.png

原文:https://stackoverflow.com/questions/47488126

更新时间:2020-02-18 23:09

最满意答案

您需要通过android闭包内的compileOptions闭包在模块的build.gradle文件中设置Java 8兼容性:

apply plugin: 'com.android.application'

android {

// other good stuff here

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}

}

You need to set Java 8 compatibility in your module's build.gradle file, via the compileOptions closure inside the android closure:

apply plugin: 'com.android.application'

android {

// other good stuff here

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}

}

2017-11-25

相关问答

您可以在您的应用程序build.gradle的默认配置中添加以下行: defaultConfig{

vectorDrawables.useSupportLibrary = true

}

编辑:你还需要添加这个依赖关系,如果你还没有 dependencies {

compile 'com.android.support:appcompat-v7:26.1.0'

}

You can add the following line inside your default config o

...

首先使缓存无效并重新启动,然后清理项目并重建它.hop有帮助。 First Invalidate caches and restart, then clean the project and rebuild it .hope it helps.

你的错误是: Multiple dex files define Lorg/apache/commons/io/filefilter/AgeFileFilter

两个(或许更多)依赖项提供了一个org.apache.commons.io.filefilter.AgeFileFilter类。 由于您碰巧在您的dependencies compile 'org.apache.commons:commons-io:1.3.2' ,因此该库肯定会提供此类。 无论如何,在我的项目中使用这个库没有发生错误?

...

我也遇到了同样的问题并解决了它。 尝试将Realm插件更新到4.2.0。 请参阅RealmTransformer中未发布的文件句柄·问题#5521·realm / realm-java I also encountered the same problem and solved it. Try to update Realm plugin to 4.2.0. See File handles are not released in RealmTransformer · Issue #5521 ·

...

它在Android Studio中称为Folding 。 首先确保它在config中启用(它应该是默认的)。 转到File - > Settings ,然后在IDE Settings区域下找到Editor -> Code Folding ,选中Show code folding outline 。 要折叠/展开项目,请使用“ Code - > Folding菜单。 编辑: 要自定义这些打开的设置( File - > Settings )的键盘快捷键,然后在IDE Settings下选择Keymap

...

基本上你需要运行lint .. 在Android Studio中,只要编译程序,就会自动运行已配置的lint和其他IDE检查。 您还可以通过从应用程序或右键单击菜单中选择“分析”>“检查代码”,在Android Studio中手动运行检查。 将出现“指定检查范围”对话框,以便您指定所需的检查配置文件和范围。 basically you need to run the lint.. In Android Studio, the configured lint and other IDE inspec

...

删除文件开头的“10_”可以解决问题。 由于您不能拥有带有数字名称的资源,请阅读此内容 。 如果这些可绘制的资源是图标,您可以使用您可以在此处阅读的常用命名约定,并通过“ic_”或“ic_menu”开始您的图标,如果这是菜单图标和操作栏图标。 removing the "10_" at the beginning of your files can fix the issue. For the reason why you can't have a resource with a numeric

...

我遇到了同样的错误,就像您一样,我没有将Twitter指定为可用的登录提供程序之一。 通过将Twitter SDK库添加到应用程序依赖项,我能够消除错误: implementation ("com.twitter.sdk.android:twitter-core:3.0.0@aar") {

transitive = true

}

I was getting the same error, and like you, I am not specifying Twitter as one o

...

我已经解决了这个问题,事实证明,问题的原因是在编写必要的依赖项(在模块build.gradle文件中)之后将库导入JAR / AAR文件以获得相同的库; 因此,在删除JAR / AAR文件后,我的应用程序能够运行 I've solved the issue, as it turns out, the cause of the problem was importing JAR/AAR files as libraries AFTER writing the necessary dependenci

...

您需要通过android闭包内的compileOptions闭包在模块的build.gradle文件中设置Java 8兼容性: apply plugin: 'com.android.application'

android {

// other good stuff here

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility Java

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值