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
}

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

相关推荐
代码s贝多芬的音符21 小时前
ios android 小程序 蓝牙 CRC16_MODBUS
android·ios·小程序
2501_915918411 天前
iOS 混淆实战 多工具组合完成 IPA 混淆、加固与工程化落地(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·ios·小程序·https·uni-app·iphone·webview
雨白1 天前
让协程更健壮:全面的异常处理策略
android·kotlin
Jeled1 天前
AI: 生成Android自我学习路线规划与实战
android·学习·面试·kotlin
游戏开发爱好者81 天前
如何系统化掌握 iOS 26 App 耗电管理,多工具协作
android·macos·ios·小程序·uni-app·cocoa·iphone
shaominjin1231 天前
android在sd卡中可以mkdir, 但是不可以createNewFile
android·开发语言·python
AI科技星1 天前
垂直原理:宇宙的沉默法则与万物运动的终极源头
android·服务器·数据结构·数据库·人工智能
用户41659673693551 天前
Kotlin Coroutine Flow 深度解析:剖析 `flowOn` 与上下文切换的奥秘
android
2501_915921431 天前
运营日志驱动,在 iOS 26 上掌握 App 日志管理实践
android·macos·ios·小程序·uni-app·cocoa·iphone
沐怡旸1 天前
【Android】详细讲解ViewDragHelper的实现原理(不含代码版)
android