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
}

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

相关推荐
2501_915918413 小时前
uni-app 项目 iOS 上架效率优化 从工具选择到流程改进的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
云梦谭3 小时前
Cursor 编辑器:面向 AI 编程的新一代 IDE
ide·人工智能·编辑器
00后程序员张3 小时前
如何在不同 iOS 设备上测试和上架 uni-app 应用 实战全流程解析
android·ios·小程序·https·uni-app·iphone·webview
米豆同学5 小时前
SufraceFlinger图像合成原理(3)-SurfaceFlinger中Layer的创建和销毁
android
米豆同学5 小时前
SufraceFlinger图像合成原理(2)-SurfaceFlinger与应用进程间的通信
android
用户2018792831675 小时前
uses-library:系统应用报NoClassDefFoundError问题
android
叽哥5 小时前
Kotlin学习第 4 课:Kotlin 函数:从基础定义到高阶应用
android·java·kotlin
mg6685 小时前
安卓玩机工具----安卓“搞机工具箱”最新版 控制手机的玩机工具
android·智能手机
诺诺Okami5 小时前
Android Framework- Activity启动2
android