Android Studio适配butterknife遇到的坑

升级Android Studio到Android Studio Narwhal 3 Feature Drop | 2025.1.3

适配butterknife遇到了各种各样的问题,差点都要放弃了,关关难过关关过

1.@BindView(R.id.xxx)无法识别

解决方案:整理项目配置

a.工程项目根路径build.gradle增加:

复制代码
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'

b.主项目路径下build.gradle增加:

复制代码
apply plugin: 'com.jakewharton.butterknife'
configuration.dependencies.add(getProject().dependencies.create('com.jakewharton:butterknife:10.1.0'))

kapt 'com.jakewharton:butterknife-compiler:10.2.3'
implementation 'com.jakewharton:butterknife:10.2.3'

2.Incorrectly typed data found for annotation element public abstract int butterknife.BindView.value() (Found data of type R2.id)

解决方案:在AndroidManifest.xml增加packagename

复制代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.xxx.xxx"
    xmlns:tools="http://schemas.android.com/tools">

3.onClick方法中使用switch case报R.id.xxx不是常量

解决方案:工程项目根路径gradle.properties增加:

复制代码
android.nonFinalResIds=false

4.无法生成BuildConfig类:

解决方案:主项目路径下build.gradle增加:

复制代码
buildFeatures {
    buildConfig  true
}

赠人玫瑰手有余香,欢迎大家一起交流讨论,让码农的工作越来越简单!

相关推荐
Coffeeee4 小时前
如何使用Glide和Coil加载WebP动图
android·kotlin·glide
Kapaseker5 小时前
5 分钟搞懂 Kotlin DSL
android·kotlin
恋猫de小郭5 小时前
AI Agent 开发究竟是啥?如何用 AI 开发 Agent ?深入浅出给你一套概念
android·前端·ai编程
黄林晴5 小时前
Android 17 正式发布!target 37 一大批旧代码直接不能用了
android
Carson带你学Android5 小时前
Android 17 正式发布:AI 终于成了系统能力
android·前端·ai编程
三少爷的鞋6 小时前
当 UseCase 开始长期监听,它可能已经不是 UseCase 了
android
恋猫de小郭19 小时前
Android 限制侧载新进展,谷歌联合国内厂商推验证计划
android·前端·flutter
恋猫de小郭19 小时前
解读 Android 17 全新内存限制,有没有“豁免”后门?
android·前端·flutter
贾艺驰1 天前
实战Android Framework: 新增一个系统权限
android
alexhilton1 天前
使用Android Archive进行打包
android·kotlin·android jetpack