关于Static interface methods are only supported starting with Android N (--min-api 24)错误

@[TOC](关于Static interface methods are only supported starting with Android N (–min-api 24)错误)
项目使用Androidx时遇到的一些问题

错误一

Static interface methods are only supported starting with Android N (--min-api 24)

大概意思就是静态接口方法只从Android N开始使用。

错误二

Invoke-customs are only supported starting with Android O (–min-api 26) 
Message{kind=ERROR, text=Invoke-customs are only supported starting with Android O (–min-api 26)

意思就是这些东西从Android O开始支持使用。

然后我查了一下相关资料,发现这两个问题的原因出自同一个。

解决方法如下:

因为静态接口需要在Java 8 下才支持使用,所以我们要使用静态接口,就需要在app的build.gradle文件中配置声明,使用Java 8编译。

所以需要加入以下代码来声明:


compileOptions {
 
    sourceCompatibility JavaVersion.VERSION_1_8
 
    targetCompatibility JavaVersion.VERSION_1_8
 
}

Androidx中使用butter knife

遇到 错误: 程序包android.support.annotation不存在

import android.support.annotation.CallSuper;
import android.support.annotation.UiThread;

原因:在项目中使用了butterknife,也就是说butterknife中没有转Androidx;
解决办法:使用9以上的版本,我是改成10.0.0,就没有问题了

 implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'