-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support non-final IDs #605
Comments
One concern that came up in previous solutions was using getIdentifier makes the generated code potentially incorrect if an ID is changed without changing the annotation. #591 uses the generated R class directly, so invalid IDs cause a compile-time error. |
@GrahamRogers If you want to use ButterKnife in a library project, maybe you can check this plugin project: ButterCookie |
@JackCho we don't use Gradle to build apps, so a Gradle plugin won't help. Thanks for the suggestion though. |
Great to see work going on in this regard. We faced the same problem recently when trying to build with buck/bazel. I am trying out an alternate approach (not a gradle plugin) that allows using non final ids in butterknife i.e support for libraries for all bind annotations including extensions. Will open a PR soon :) This approach also does not need any modifications to the annotation classes themselves, so I believe it may be cleaner than what is proposed in #591 |
@JackCho I looked in more detail at your ButterCookie project and I thought I should let you know that making all the ButterFork appears to be a safer alternative, it generates a #497 and #573 are interesting, extension support for ButterKnife. While the pull request only supports listeners for now, if it was made to be more flexible it would be possible to create an extension for non-final IDs, allowing the implementation to be in a separate project from ButterKnife (and hence not be officially endorsed by the team). I think that would be the best long-term solution. |
@GrahamRogers maybe you didn't follow ButterCookie completely, ButterCookie as a gradle plugin, it does the following five things, not just the first one: so good to go... |
@JakeWharton you may check this issue, supporting non-final ids does really work here, and nothing is changed when using ButterKnife |
@GrahamRogers I am planning to open a PR this weekend with full library support using gradle with extensible hooks for both buck and bazel. It would also support all butterknife-extensions out of the box. I suggest you to check it out |
@GrahamRogers See #613 |
Support is on |
I know this was covered in #2, but I have a real use case for it.
In our app, we retain presenters across configuration changes using a retained fragment. However, we don't want the presenters to have to care about views being destroyed and recreated, so we have a "view manager" object which implements the View interface and manages the View's lifecycle, like a mini-fragment.
Our view managers implement an interface like this:
Then an implementation would look something like:
I think it's clear how this model would benefit from Butter Knife - a more complicated view would have many calls to
findViewById
and would have to remember to set all view fields tonull
inonDestroyView
.Now, the reason I need non-final ID support is because of the build system we use at Google. The recommended practice is to create an Android library for every package rather than one big build target. This allows us to have package-specific resources and improves build times by caching builds. However, this means that all of our IDs are non-final, which means we cannot use Butter Knife without support for non-final IDs.
I have created #591 to add support, take a look and let me know what you think. It may also be possible to use the extensions feature proposed in #573, but that hasn't been updated in over two weeks.
The text was updated successfully, but these errors were encountered: