Butterknife: Build fails with Android Studio 3.0 and Butter Knife 9.0.0-SNAPSHOT

Created on 9 Nov 2017  ·  9Comments  ·  Source: JakeWharton/butterknife

So I searched through all related issues and tried the proposed solutions but I cannot get it to work. I am using Android Studio 3.0 stable and this is my setup:

Project level build.gradle:

buildscript {
    repositories {
        jcenter()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App module build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'

android {
    repositories {
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}
dependencies {
    compile 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
}

Gradle sync succeeds normally, but when I try to build the project I get this error message in Gradle console:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'.
> Could not resolve com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT.
  Required by:
      project :app
   > No cached version of com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT available for offline mode.

Offline work in Android Studio global Gradle settings is TURNED OFF:
image

Most helpful comment

@kassim I also suspected that somehow offline mode is turned on but I didn't know how to check it.
 
Finally I managed to make it work by adding --refresh-dependencies command line option to the compiler (_Android Studio > Preferences > Build, Execution, Deployment > Compiler_).

All 9 comments

@Tforandroid It makes no difference and I have already jcenter() added to all projects in project level build.gradle anyway:

allprojects {
    repositories {
        jcenter()
        google()
    }
}

this is my setting ,you can copy it
Projects build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
google()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

moudle build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
.....
dependencies {
........
//butterknife
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

@Tforandroid I think my problem lies in gradle 3.0.0. with older version 2.3.3 (like the one you use) everything worked ok.

have you checked the build commands in the gradle console to check if Android Studio is actually respecting that you don't want to run gradle offline?
"no cached version" sounds like its not

maybe run ./gradlew androidDependencies on the command line

@kassim I also suspected that somehow offline mode is turned on but I didn't know how to check it.
 
Finally I managed to make it work by adding --refresh-dependencies command line option to the compiler (_Android Studio > Preferences > Build, Execution, Deployment > Compiler_).

I also find out that in compiler options --offline is set. After deleting this option builds successfully.

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

In case like me you are confused about the gradle settings, you can find the complete solution to this as a stack overflow answer: https://stackoverflow.com/a/52308912/10224384

Was this page helpful?
0 / 5 - 0 ratings