Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impact to ButterKnife from "Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them as annotation attributes"

I'm using annotated attributes all over my Android project to bind Views and events to fields and methods.

@BindView(R.id.textViewOrderId)
TextView textViewOrderId;

@OnClick(R.id.buttonDateFilter)
public void onButtonDateFilter(View view) {...}

Migrating out of ButterKnife has become a bit expensive now. I would like to clarify a few things about this new Gradle Plugin change,

  • How will non-final resource ids affect my current project?
  • Will I have to migrate out of ButterKnife for good if I update the Gradle Plugin?
  • How effective is the R2 class mentioned in this Reddit post?
like image 793
Roshana Pitigala Avatar asked Oct 14 '20 12:10

Roshana Pitigala


2 Answers

This still has no answer. But I suppose there is no option but to replace ButterKnife with an alternative, most probably View Binding.

As it states in this article, View Binding Tutorial for Android: Getting Started:

Additionally, ButterKnife’s development is coming to an end. Jake Wharton, the creator of this library, is deprecating it in favour of View Binding.

From the ButterKnife GitHub page:

Attention: This tool is now deprecated. Please switch to view binding. Existing versions will continue to work, obviously, but only critical bug fixes for integration with AGP will be considered. Feature development and general bug fixes have stopped.

like image 179
Big_Chair Avatar answered Oct 22 '22 08:10

Big_Chair


As suggested by Jake Wharton, you can apply the butterknife-plugin and use R2 instead of R to access resource ids.

like image 5
Ridcully Avatar answered Oct 22 '22 09:10

Ridcully