butterknife: Missing resource ID
I’m running:
- Android Studio 2.3.3
- Kotlin 1.1.2-3
- Butterknife 8.6.0
My project has an app module an a library module, in the app module I’ve included:
dependencies {
...
compile "com.jakewharton:butterknife:$butterknife_version"
kapt "com.jakewharton:butterknife-compiler:$butterknife_version"
}
In the library module I have:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jakewharton:butterknife-gradle-plugin:$butterknife_version"
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
...
}
dependencies {
...
compile "com.jakewharton:butterknife:$butterknife_version"
kapt "com.jakewharton:butterknife-compiler:$butterknife_version"
}
My library code includes a custom view called CameraControlView with the following:
@OnClick(R2.id.switch_camera)
fun switchCamera() {
}
The generated CameraControlView_ViewBinding.java has the following offending line:
view = Utils.findRequiredView(source, 2131493059, "method 'switchCamera'");
R2.id.switch_camera is 0x7f0c00c3 (2131493059) R.id.switch_camera is 0x7f0c00c3 in library R.id.switch_camera is 0x7f100186 in app
Am I configuring butterknife wrong for the library or is this a bug?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 39 (10 by maintainers)
@newtalentxp 大哥!你是键盘侠吗?不要公开丢中国人脸。
OnClickannotation is not working for me in library module. Is that the same problem as described here or should I create a separate issue?ButterKnife: 9.0.0-SNAPSHOT Kotlin: 1.2.40 AGP: 3.1.2
For the following class
ButterKnife generates
At runtime I’m receiving
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource IDI noticed, that for
@BindViewgenerated code contains reference toR.id. But for@OnClickgenerated code contains hardcoded constant.UPDATE: I also noticed that sometimes it happens like that, but sometimes binding for
OnCLickis generated with reference toR.id.@newtalentxp wowow easy man
I have just tested Kotlin 1.3.20 (stable) with Butterknife 9.0.0 on library modules, and everything seems to be working fine! 👍
It’s fixed in 1.3.20
On Fri, Nov 16, 2018, 10:30 AM Daniel Frett <notifications@github.com wrote:
the problem is still here, not fixed, fuck
Do you mean that R2 should contain something like
switch_camera = com.example.R.id.switch_camera?The generated R2 contains:
Library R contains:
App R contains: