java 为什么我在 Android Studio 3.0 中遇到“com.jakewharton:butterknife:7.0.1”的问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47087730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:30:01  来源:igfitidea点击:

Why do I have problems whith 'com.jakewharton:butterknife:7.0.1' in Android Studio 3.0?

javaandroidbutterknife

提问by Héctor DlaCruz III

I have the following problem when I run the 'app' (Android studio emulator):

我在运行“应用程序”(Android Studio 模拟器)时遇到以下问题:

Error:Execution failed for task ':app:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

My Graddle-App Level:

我的 Gradle 应用程序级别:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.hhhhh.android"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    implementation 'com.google.firebase:firebase-database:11.0.4'
    implementation 'com.google.firebase:firebase-auth:11.0.4'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'

}

apply plugin: 'com.google.gms.google-services'


The error disappears when I switch to the version:

当我切换到版本时错误消失:

compile 'com.jakewharton:butterknife:8.7.0'

But it generates more problems in my LogginActivity:

但它会在我的 LogginActivity 中产生更多问题:

package com.sourcey.materiallogindemo;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.ButterKnife;
import butterknife.Bind;

public class LoginActivity extends AppCompatActivity {
    private static final String TAG = "LoginActivity";
    private static final int REQUEST_SIGNUP = 0;

    @Bind(R.id.input_email) EditText _emailText;
    @Bind(R.id.input_password) EditText _passwordText;
    @Bind(R.id.btn_login) Button _loginButton;
    @Bind(R.id.link_signup) TextView _signupLink;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

        _loginButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                login();
            }
        });

        _signupLink.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // Start the Signup activity
                Intent intent = new Intent(getApplicationContext(), SignupActivity.class);
                startActivityForResult(intent, REQUEST_SIGNUP);
                finish();
                overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
            }
        });
    }

    public void login() {
        Log.d(TAG, "Login");

        if (!validate()) {
            onLoginFailed();
            return;
        }

        _loginButton.setEnabled(false);

        final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
                R.style.AppTheme_Dark_Dialog);
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage("Authenticating...");
        progressDialog.show();

        String email = _emailText.getText().toString();
        String password = _passwordText.getText().toString();

        // TODO: Implement your own authentication logic here.

        new android.os.Handler().postDelayed(
                new Runnable() {
                    public void run() {
                        // On complete call either onLoginSuccess or onLoginFailed
                        onLoginSuccess();
                        // onLoginFailed();
                        progressDialog.dismiss();
                    }
                }, 3000);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_SIGNUP) {
            if (resultCode == RESULT_OK) {

                // TODO: Implement successful signup logic here
                // By default we just finish the Activity and log them in automatically
                this.finish();
            }
        }
    }

    @Override
    public void onBackPressed() {
        // Disable going back to the MainActivity
        moveTaskToBack(true);
    }

    public void onLoginSuccess() {
        _loginButton.setEnabled(true);
        finish();
    }

    public void onLoginFailed() {
        Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show();

        _loginButton.setEnabled(true);
    }

    public boolean validate() {
        boolean valid = true;

        String email = _emailText.getText().toString();
        String password = _passwordText.getText().toString();

        if (email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            _emailText.setError("enter a valid email address");
            valid = false;
        } else {
            _emailText.setError(null);
        }

        if (password.isEmpty() || password.length() < 4 || password.length() > 10) {
            _passwordText.setError("between 4 and 10 alphanumeric characters");
            valid = false;
        } else {
            _passwordText.setError(null);
        }

        return valid;
    }
}

With 8.7.0:

使用 8.7.0:

enter image description here

在此处输入图片说明

回答by OneCricketeer

Annotation processors must be explicitly declared now

现在必须显式声明注释处理器

Do what it says

做它说的

Add the second line

添加第二行

compile 'com.jakewharton:butterknife:8.7.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'

With 8.7.0 ... it generates more problems in my LogginActivity:

使用 8.7.0 ... 它会在我的 LogginActivity 中产生更多问题:

You are importing the wrong class...

您正在导入错误的类...

Annotate fields with @BindView

使用@BindView 注释字段

That changed at Version 8.0

这在 8.0 版发生了变化

See the website for usage and the latest version. http://jakewharton.github.io/butterknife/

有关使用方法和最新版本,请参阅网站。http://jakewharton.github.io/butterknife/

import butterknife.BindView;

..

@BindView(R.id...)

回答by krishnamurthy

you can solve this issue by simply adding this to your app level gradle file

您可以通过简单地将其添加到您的应用程序级 gradle 文件来解决此问题

android{
....
    defaultConfig{
....
    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
}

Hope its worked

希望它的工作

回答by Thientvse

You can try :

你可以试试 :

// butter knife
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

Otherwise you can try

否则你可以试试

https://github.com/avast/android-butterknife-zelezny

https://github.com/avast/android-butterknife-zelezny

to auto gencode from butterknife.

从黄油刀自动生成代码。

I hope it can help your problem!

我希望它可以帮助您解决问题!

回答by Nongthonbam Tonthoi

Just add this line:

只需添加这一行:

annotationProcessor 'com.jakewharton:butterknife-compiler:7.0.1'

in your dependencies like:

在您的依赖项中,例如:

dependencies {
    //...
    compile 'com.jakewharton:butterknife:7.0.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:7.0.1'
}

Check thisout for more details.

查看了解更多详细信息。

回答by Android Geek

try this ,you need to add the annotation along with ButterKnife library..

试试这个,你需要和 ButterKnife 库一起添加注释..

Butterknife library

黄油刀图书馆

 compile 'com.jakewharton:butterknife:8.8.1'

annotation for butterknife

黄油刀的注释

annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'