[Android Gradle plugin 3.0.0 must not be applied] [getOutputs()Ljava/util/List]

2019-05-25 13:10:04 浏览数 (1)

代码语言:javascript复制
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

代码语言:javascript复制
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顶部加这两句

代码语言:javascript复制
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

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

代码语言:javascript复制
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中改为如下

代码语言:javascript复制
buildscript {
  repositories {
        // ...
    }
    dependencies {
        // ...
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
    }
}

0 人点赞