ButterKnife 8.0.1 not working

前端 未结 10 1155
粉色の甜心
粉色の甜心 2020-12-05 16:42

I am using butterknife 8.0.1, but a nullpointerexception is appearing.

This line is on my build.grade file: compile \'com.ja

相关标签:
10条回答
  • 2020-12-05 17:27
    App Level(build.gradle)
    
    apply plugin: 'android-apt'
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:24.2.1'
        testCompile 'junit:junit:4.12'
        compile 'com.jakewharton:butterknife:8.4.0'
        apt 'com.jakewharton:butterknife-compiler:8.4.0'
    }
    
    
    Project Level(build.gradle)
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
    
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    0 讨论(0)
  • 2020-12-05 17:31

    Config Butterknife on build.gradle file like this,

    compile("com.jakewharton:butterknife:8.5.1")
    annotationProcessor "com.jakewharton:butterknife-compiler:8.5.1"
    

    It works for me.

    0 讨论(0)
  • 2020-12-05 17:33

    I used this library in Fragment and has NPE. My code was:

    ButterKnife.bind(view);
    

    But it was wrong. Library need to know two objects:
    1) Target - with annotations @BindView
    2) Source - with views

    It will be right to write:

    ButterKnife.bind(this, view);
    

    When this - your fragment, and view - view of this fragment.

    0 讨论(0)
  • 2020-12-05 17:37

    I had this issue too, just because I've added butterknife from Android Studio's Dependency management and not by copy-pasting gradle lines from Butterknife website. So I had to add compile 'com.jakewharton:butterknife:8.5.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' instead of just compile 'com.jakewharton:butterknife:8.5.1'

    0 讨论(0)
  • 2020-12-05 17:37

    If you use kotlin:

    make sure to use this dependency in module app:

    dependencies {
       implementation 'com.jakewharton:butterknife:10.0.0'
       kapt 'com.jakewharton:butterknife-compiler:10.0.0'
    }
    
    0 讨论(0)
  • 2020-12-05 17:37

    From JakeWharton

    Yes that plugin is no longer needed. You're already using annotationProcessor for the 'butterknife-compiler' artifact which is built-in to the Android Gradle plugin.

    Then the solution is delete apt classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

    0 讨论(0)
提交回复
热议问题