how to add plugin 'butterknife' to project [Android Gradle plugin 3.0.0 must not be applied] [getOutputs()Ljava/util/List]


what is butterknife?

butterknife is a plugin that simplifies your binding to view components. For instance, instead of

public class MainActivity extends AppCompatActivity {
    FloatingActionButton fab;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(...);
    // ...

you can simply do it in this way

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.fab) FloatingActionButton fab;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this);

        fab.setOnClickListener(...);
    // ...

there are more features in this plugin. you can view it in this page https://github.com/JakeWharton/butterknife

接下来楼主懒得用英文了感觉还是中文好读


安装时可能遇到的问题

Error:(3, 0) Android Gradle plugin 3.0.0 must not be applied to project since version 3.0.0 was already applied to this project

官方文档让我们在module的gradle顶部加这两句

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

我通过删掉下面这句,解决了问题

apply plugin: 'com.android.library'

Gradle sync failed: Cause: com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;

楼主写文章时, 最新版本是8.8.1, 我通过改成使用8.4.0版本解决了问题。
在项目的gradle中改为如下

buildscript {
  repositories {
        // ...
    }
    dependencies {
        // ...
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容