Butterknife: @BindDimen weird bug

Created on 26 Aug 2015  Â·  19Comments  Â·  Source: JakeWharton/butterknife

Have this weird bug where lint will throw an exception about @BindDimen

I had this line and it worked fine till now

@BindDimen(R.dimen.divider_margin)
int dividerMargin;

Now lint sometimes fails. Not sure if it's an issue with AS or with butterknife. Attaching lint result
screen shot 2015-08-26 at 1 11 33 am

Most helpful comment

For the time being I'd recommend adding this to your lint.xml

    <issue id="ResourceType">
        <!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
        <ignore path="**/*$$ViewBinder.java" />
    </issue>

All 19 comments

I'll emit suppressions on the generated code. The next version will add @DimenRes to the @BindDimen (and other) annotations so it will be lint-impossible to pass the wrong value anyway and the check will happen at the right place.

This is blocked by #330.

Any idea why it fails some of the times?

Nope. No clue.

On Tue, Aug 25, 2015 at 6:31 PM Arthur [email protected] wrote:

Any idea why it fails some of the times?

—
Reply to this email directly or view it on GitHub
https://github.com/JakeWharton/butterknife/issues/338#issuecomment-134760774
.

Closing the issue then. Maybe we'll find out in the next version

@c0nnector do you use retrolambda and android-retrolambda-lombok? I just added those two to a project and had this error for the first time.

@gabrielittner Not using retrolamda

Is it possible that the ID changes and the generated class is not invalidated?

Ah, probably. It's a shame we can't get the reference to the actual R
constant (without epic hacks).

On Wed, Aug 26, 2015 at 5:22 PM Tom Reznik [email protected] wrote:

Is it possible that the ID changes and the generated class does not get
invalidated?

—
Reply to this email directly or view it on GitHub
https://github.com/JakeWharton/butterknife/issues/338#issuecomment-135173773
.

I think it's an AS studio issue. Started after i updated to AS 1.4 preview 3

Ok, got some clarification. Lint analyses sources as text files (maybe also class files). When I've tried to put in sources not constant reference but its value I got already error in AS:
screenshot 2015-08-27 07 16 38

Would adding //noinspection ResourceType to the generated ViewBinder fix this? I'm seeing it as well.

For the time being I'd recommend adding this to your lint.xml

    <issue id="ResourceType">
        <!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
        <ignore path="**/*$$ViewBinder.java" />
    </issue>

Just to clarify, the lint.xml file should be on your-project-folder/app/lint.xml

Hmm. I started getting this error with butterknife-8.2.1. Using kapt (dunno if this is related).

Can this be a regression?

Though it's not @BindDimen as in original issue, but @BindView

Checking in to say that I get lint errors on 8.2.1 related to @BindView as well. @felipecsl's solution worked for me, but I had to change the path to **/*_ViewBinding.java:

<issue id="ResourceType">
    <!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
    <ignore path="**/*_ViewBinding.java" />
</issue>

Currently experiencing this issue on 8.4.0 The following open source repository at this commit can reproduce the error 100% of the time: https://github.com/AOrobator/Konstellations/commit/6ff414762c20158e7dab3d383e05e6960d029fed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

momochenxx picture momochenxx  Â·  3Comments

ZakTaccardi picture ZakTaccardi  Â·  3Comments

galibimtiaz picture galibimtiaz  Â·  3Comments

mturki picture mturki  Â·  3Comments

Pitel picture Pitel  Â·  3Comments