Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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:

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:

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:

enter image description here

like image 675
Héctor DlaCruz III Avatar asked Nov 03 '17 02:11

Héctor DlaCruz III


People also ask

Why doesn't butterknife-compiler JAR file exist?

Then we run into the issue that butterknife-compiler 5.5.1 JAR file doesn't exist (probably the same problem @configurer encountered), because ButterKnife didn't include butterknife-compiler until ButterKnife version 8.2.0. We could upgrade to ButterKnife 8.2.0 or later. But ButterKnife uses @BindView in the latest version, instead of @InjectView.

Can I upgrade the butterknife library?

Alternatively, you could instead upgrade the ButterKnife library, but for us that entailed a lot of refactor renaming, and an unknown amount of extra upgrade work, so it was not desirable at this time. App crashes on Android mobiles on startup.

What version of Android Studio do you use with Classpath?

Quick fix: Downloaded Android Studio 2.3.2 instead, and verified the build works there, when using classpath 'com.android.tools.build:gradle:2.3.2' Was actually able to use Android Studio 3.0 with this small change to the app/build.gradle file (to make it work like in Android Studio 2.3.2):

Does butterknife use @injectview instead of @BindView?

But ButterKnife uses @BindView in the latest version, instead of @InjectView. So if we upgrade ButterKnife to 8.2.0 or later, then we have to rename all the instances of @InjectView to @BindView in 100+ places in 17+ files, and potentially have to make other changes too.


1 Answers

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:

You are importing the wrong class...

Annotate fields with @BindView

That changed at Version 8.0

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

import butterknife.BindView;

..

@BindView(R.id...)
like image 135
OneCricketeer Avatar answered Oct 25 '22 06:10

OneCricketeer