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
}

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

相关推荐
诸神黄昏EX30 分钟前
Android Google KEY
android
一起搞IT吧36 分钟前
Android性能系列专题理论之十一:block IO问题分析思路
android·嵌入式硬件·智能手机·性能优化
小妖6661 小时前
怎么用 tauri 创建编译 android 应用程序
android·tauri
lifewange1 小时前
Pycharm和IDEA中安装Cursor的方法
ide·pycharm·intellij-idea
鸟儿不吃草3 小时前
安卓实现左右布局聊天界面
android·开发语言·python
xxjj998a4 小时前
Laravel 1.x:PHP框架的原始魅力
android·php·laravel
formula100004 小时前
在iOS/安卓上远程连接任何 Agent!Claude、Codex、Copilot、Gemini、OpenCode 等
android·copilot
该用户可能存在4 小时前
Blbl-android 更新至 v0.1.24,体验更流畅、更稳定
android·哔哩哔哩·电视app·androidtv·bbll·blbl·bilibilitv
lKWO OMET5 小时前
mysql之字符串函数
android·数据库·mysql
liang_jy15 小时前
Android SparseArray
android·源码