对butterknife的版本要求
Android Studio3.3配置butterknife对版本有要求,9.0.0-r2以上

但butterknife10.0.0只支持Androidx
As mentioned in the change log, 10.0.0 only supports AndroidX-enabled projects. If you have not yet migrated to AndroidX you need to use 9.0.0 for now.
如果没有使用androidx配置butterknife10.0.0会报这个异常
[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)
这里的配置没有使用androidx,是android
gradle脚本配置
project脚本
buildscript {
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module脚本
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "pdsu.xps.blacklisttest"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.jakewharton:butterknife:9.0.0-rc1'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
}
module脚本注意
如果出现如下错误
Error: Static interface methods are only supported starting with Android N (--min-api 24): void butterknife.Unbinder.lambda$static$0()
在module脚本中的android或defaultConfig中添加以下内容,或可解除错误
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
本文介绍了Android Studio 3.3配置Butterknife的注意事项,强调版本要求为9.0.0-r2以上,并指出butterknife 10.0.0仅支持AndroidX项目。对于未迁移至AndroidX的项目,需要使用9.0.0版本。同时,提供了gradle脚本配置的详细步骤,包括project脚本和module脚本的修改,以解决可能出现的配置错误。

1万+

被折叠的 条评论
为什么被折叠?



