Butterknife Suddenly Stopped Working

Viewed 860

Yesterday I was working on my on going project using butterknife in it.But suddenly its stopped working.The ButterKnife.bind(this) is not able to bind the views so that all the views are throwing NullPointerException.I don't understand what happened that suddenly its stop working.Its a weird situation

Here are few points which i already did but its not working

  1. Using Latest version currently i am using 8.8.1
  2. Using old version i tried with 8.0.1 and 8.6.0
  3. Clean and Rebuild
  4. Invalidate Cache
  5. Removing Gradle and Build files

Following are the version i am using

ext {
    // sdk and tools
    minSdkVersion = 21
    targetSdkVersion = 27
    compileSdkVersion = 27
    buildToolsVersion = '26.0.2'

    // dependencies versions
    supportLibraryVersion = '27.0.0'
    playServicesVersion = '10.2.4'
    butterKnifeVersion = '8.8.1'
    retrofitVersion = '2.3.0'

}

I am banging my head from past 8 Hours on this silly issue.If anyone could help will be appropriated

2 Answers

Finally i found the solution.Ii was due to Kotlin Plugin. It was happening since I updated the Kotlin plugin in Android Studio 3.0

If you are using Kotlin then annotationProcessor wont work instead you need to use kapt

So replace this

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

with this

compile 'com.jakewharton:butterknife:8.8.1'
kapt'com.jakewharton:butterknife-compiler:8.8.1'

It will resolve the issue

There can be 2 possibilities:

  1. Your external dependency is not upgraded, check "External Libraries" section of your project and compare if it is upgraded to latest version or not i.e. 8.8.1 (also try to make gradle offline work)
  2. If you are upgraded to Android plugin for Gradle 3.0 or higher than your project automatically uses default version of buildTools https://developer.android.com/studio/releases/build-tools.html#notes
Related