在Androidx下如何使用butterknife注解框架

本文分享了在Androidx下使用butterknife注解框架的踩坑记录。包括安装butterknife插件,在build.gradle(Project)和build.gradle(Module)中添加代码及注入依赖,完成框架配置。还提醒在Androidx中butterknife版本要用10.2.1及以上或用“+”。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

相信好多同学在Androidx下使用butterknife注解框架时会遇到各种坑,下面分享下我的踩坑记录,希望可以帮助到大家


1.安装butterknife插件
这一步骤相信大家都可以自己完成,最主要的是下面几个步骤

2.在build.gradle(Project: )中添加如下代码

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // 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
}

3.在build.gradle(Module: )中
1).在本页面最上面加入下面这行代码

apply plugin: 'com.jakewharton.butterknife'

2).注入依赖

android {
  ...
  // Butterknife requires Java 8.
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

dependencies {
  implementation 'com.jakewharton:butterknife:10.2.3'
  annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}

这样我们就完成了框架的配置工作,接下来快去你的代码中体验一下吧

备注:在Androidx中butterknife的版本请使用10.2.1及以上的版本或者使用“+”也可以,切记切记

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值