Butterknife @generate not working{Error:(23, 6) error: cannot find symbol class Bind}

Butterknife @generate not working{Error:(23, 6) error: cannot find symbol class Bind}

build.grable(root)app

apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
    minSdkVersion 18
    targetSdkVersion 23
    multiDexEnabled true
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner    "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),          'proguard-rules.pro'
    }
}
productFlavors {
}
dexOptions {
    incremental true
    javaMaxHeapSize '2g'
    jumboMode = true
    preDexLibraries =true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:support-annotations:25.3.0'
androidTestCompile 'com.android.support:support-annotations:25.3.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}

build.gradle

package com.pocketfeeds.app1;

import android.app.ProgressDialog;
import android.content.res.Configuration;
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;
}
}

Error:Execution failed for task':app1:compileReleaseJavaWithJavac'.Compilation failed;see the compiler error output for details.'

要确认上面评论中提到的 Tim,您需要将以下内容添加到 build.gradledependencies 部分:

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

虽然启用了 ButterKnife 库,但 Java 编译器无法处理 @Bind 注释,因为尚未启用 ButterKnife 注释处理器。此注释处理器将 ButterKnife 特定的语句扩展为 Android 可以本机理解的格式。

还要确保在 build.gradle:

中启用了 jcenter 和 mavenCentral 存储库
repositories {
    mavenCentral()
    jcenter()
}

编辑我是个白痴。感谢 Sourav Ganguly 指出需要使用 @BindView,而不是 @Bind。我最近在 Dagger 上花了太多时间...

编辑 2:关于常量表达式错误,您还需要包含 R 文件:

import com.pocketfeeds.app1.R

在 gradle 文件中添加以下条目

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

@BindView 是用于绑定视图的键。

转到 Android Studio-> 文件 -> 设置 -> 插件 -> 浏览存储库 -> 搜索 butterknife -> 安装。

然后重新启动您的 android 工作室。

对我有用