Android Studio 3.3配置Butterknife处理

文章目录

    • 对butterknife的版本要求
    • gradle脚本配置
      • project脚本
      • module脚本
    • module脚本注意

对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脚本中的androiddefaultConfig中添加以下内容,或可解除错误

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

你可能感兴趣的:(Android)