解决ButterKnife和androidX的冲突

最近在帮助朋友新建一个新项目,在引入ButterKnife 8.8.1 的时候总是报错和androidX有冲突,查了很多资料后都是一些适配androidX,但是还是没有解决问题。

看了ButterKnife在Github上给出的代码后问题就解决了,这里还是想吐槽下自己,ButterKnife现在已经到10.2.1了我们还在使用8.8.1‍♀️  还是要及时更新项目中引用库的版本呀

ButterKnife Github地址 https://github.com/JakeWharton/butterknife  

需要在两个文件里面进行引用,1.项目的build.gradle  2.app里面的build.gradle

1.项目中build.gradle中ButterKnife引入代码(标红处)

buildscript {
    
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
2.是app层build.gradle中ButterKnife引入代码(标红处)

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "com.ansier.myedittext2"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation project(':mylibrary2')
    implementation 'com.jakewharton:butterknife:10.2.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'

}

希望对大家有所帮助

你可能感兴趣的:(android)