3

every time I try to build my project the following error occurs:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V

Follows the classes responsible for the dependency injection:

ApplicationModule

@Module
public class ApplicationModule {

    private static final String APP_ID = "id";
    private static final String APP_SECRET = "secret";

    private final Application mApplication;

    public ApplicationModule(Application application) {
        mApplication = application;
    }

    @Provides
    Application provideApplication() {
        return mApplication;
    }

    @Provides
    @Singleton
    Client provideClient(Application application) {
        return new Client.Builder(APP_ID, APP_SECRET, application).build();
    }
}

ApplicationComponent

@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {

    void inject(MainApplication application);

    Application getApplication();

    Client getClient();

}

MainApplication

public class MainApplication extends android.app.Application {

    private ApplicationComponent component;

    @Inject
    Client client;

    @Override
    public void onCreate() {
        super.onCreate();

        ...

        component = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .build();
        component.inject(this);
    }

    public ApplicationComponent getComponent() {
        return component;
    }

}

And my gradle.build (Module:app)

buildscript {
    repositories {
        jcenter()
        maven {
            url 'http://dl.bintray.com/amulyakhare/maven'
        }
    }
    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "br.mobi.santor.agora"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

final SUPPORT_LIBRARY_VERSION = '25.1.0'
final DAGGER_VERSION = '2.8'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'kinvey-android-2.10.6', ext: 'aar')

    // AppCompat dependencies
    compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
    compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
    compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
    compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"

    // Dagger dependencies
    compile "com.google.dagger:dagger:$DAGGER_VERSION"
    annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION"

    // Network dependencies
    compile 'com.squareup.picasso:picasso:2.5.2'

    // Utils dependencies
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'joda-time:joda-time:2.9.7'

    testCompile 'junit:junit:4.12'
}
Silas Ribeiro
  • 183
  • 1
  • 9
  • 1
    Based on the dagger 2 documentation you need this in your app:gradle: `apt 'com.google.dagger:dagger-compiler:2.8'`, `compile 'com.google.dagger:dagger:2.8'`, and `provided 'javax.annotation:jsr250-api:1.0'` – Rod_Algonquin Jan 29 '17 at 02:32
  • When I use `apt 'com.google.dagger:dagger-compiler:2.8'` the following error occurs `Error:(60, 0) Could not find method apt() for arguments [com.google.dagger:dagger-compiler:2.8] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.`. – Silas Ribeiro Jan 29 '17 at 10:42
  • Your preconditions error approximates the one in this thread: http://stackoverflow.com/q/40897009/1426891 . Does the advice there help? – Jeff Bowman Jan 30 '17 at 03:05
  • I was using Retrolambda, but even after removing the error it continues. – Silas Ribeiro Jan 30 '17 at 13:47

1 Answers1

3

The NoSuchMethodError almost certainly means that you have an older version of Guava on the classpath than was used to compile. Make sure that you have the latest version of Guava (almost always safe to use the latest given these compatibility guarnatees) and it should work.

gk5885
  • 3,742
  • 21
  • 16