1

I am not able to use ButterKnife.Action in andoidx, can someone give any suugestions on how to use ButterKnife.Action in androidx?

classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc2'

implementation 'com.jakewharton:butterknife:10.0.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

Kathir
  • 11
  • 2
  • what's the point to use this useless library? if you use Kotlin findVieById() is no more needed and assigning click listeners much more convenient and useful –  Sep 05 '19 at 08:00

4 Answers4

0

If you migrate to AndroidX you must use:

in gradle

dependencies {

implementation "com.jakewharton:butterknife:10.2.0"

annotationProcessor "com.jakewharton:butterknife-compiler:10.2.0"

...}

in class when you have errors

if you use code like this:

  • ButterKnife.apply(new View[]{ ivImageId,vgSubscribtionsId,vgSubscribersID},

                (view, value, index) -> view.setVisibility(value), View.INVISIBLE);
    

replace to this for work with AndroidX:

  • butterknife.Action viewAction = (view, index) -> {

            view.setVisibility(View.INVISIBLE);
    
        };
        butterknife.ViewCollections.run(new View[]{ ivImageId,vgSubscribtionsId,vgSubscribersID} , viewAction );
    
Yaroslav.P
  • 19
  • 3
0

I used the version 10.2.1 of ButterKnife . Follow these steps and the problem will be fixed.

//Step 1 : import this line

import butterknife.Action;

//Step 2 : in Scope Class

butterknife.Action viewAction = new Action() 
{

     @Override public void apply(@NonNull View view, int index) 
    {
    // do something.
    }

};

//Step 3 : ButterKnife.apply() in new version is deprecated . Replace to:

 butterknife.ViewCollections.run(listView , viewAction );
Esmaeil Ahmadipour
  • 840
  • 1
  • 11
  • 32
0
In Android studio Flamingo and above version below code working for butterknife library.

 1. add below code in build.gradle(:app) file 

    tasks.withType(JavaCompile).configureEach {
        options.fork = true
        options.forkOptions.jvmArgs += [
                '--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
                '--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED',
        ]
    }

 2. 
    android {
      ...
      // Butterknife requires Java 8.
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    }
    
    dependencies {
      implementation 'com.jakewharton:butterknife:10.2.3'
      annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
    }
    
     3. To use Butter Knife in a library, add the plugin to your buildscript:
    
    buildscript {
      repositories {
        mavenCentral()
        google()
      }
      dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
      }
    }
    
     4. and then apply it in your module:
    apply plugin: 'com.android.library'
    apply plugin: 'com.jakewharton.butterknife'
    
     5. Now make sure you use R2 instead of R inside all Butter Knife annotations.
    class ExampleActivity extends Activity {
      @BindView(R2.id.user) EditText username;
      @BindView(R2.id.pass) EditText password;
    ...
    }
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
-1

With androidX, you should use

import butterknife.ButterKnife;

and then do something like new butterknife.Action<View>()

Package name is now butterknife with a 'b' whereas before if was with a 'B'

I hope this will help ...

milanbalazs
  • 4,811
  • 4
  • 23
  • 45
Eclos
  • 1
  • 1