"Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them as annotation attributes" 对 ButterKnife 的影响

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

我在整个 Android 项目中使用带注释的属性将 View 和事件绑定到字段和方法。

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

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

从 ButterKnife 迁移出来现在变得有点昂贵。我想澄清一些关于这个新的 Gradle 插件变化的事情,

这个还是没有答案。但我想除了用替代品替换 ButterKnife 别无选择,很可能 View Binding.

正如本文所述,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.

来自 ButterKnife GitHub 页面:

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.

根据 Jake Wharton 的建议,您可以应用 butterknife-plugin 并使用 R2 而不是 R 来访问资源 ID。