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
}

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

相关推荐
三少爷的鞋5 小时前
Android 架构七条铁律:架构师真正设计的不是代码,而是秩序
android
别问!问就是全会6 小时前
Jupyter Notebook 安装包下载|单元格分块运行,图表直接内嵌
ide·python·其他·jupyter
xiangxiongfly9157 小时前
Android GsonFactory总结
android·gson·gsonfactory
WythePlus9 小时前
Android 14 SELinux策略深度解析
android·安全策略·selinux策略
俩个逗号。。12 小时前
Kotlin flow 详解
android·开发语言·kotlin
橙光成长14 小时前
android-ad-cleaner:android免 Root 批量关闭系统开屏与营销推送
android·1024程序员节
深圳雨林凯AI14 小时前
图案裂变的底色衰减:alpha通道、亮度对比与白墨分色的量化拆解
android
mmsx14 小时前
Android 模块化收口:能力组合框架、手写 LifecycleOwner 与热修复共存
android
恋猫de小郭17 小时前
Flutter 可以更直接地调用原生 API 了,Dart Direct Native Interop
android·前端·flutter
2501_9160088917 小时前
iPhone 设备信息查看,用 KeyMob 看型号、序列号、电池健康和 UDID
android·ios·小程序·https·uni-app·iphone·webview