Dagger 2 does not generate components

Asked

Viewed 67 times

0

Every time I try to give build in 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 my classes responsible for the injection of dependency:

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 mine Gradle.build (Module:app)

apply plugin: 'com.android.application'

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'
        }
    }
}

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'
}

build.Gradle (Module:project)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • Silas, this seems to me an incompatibility of Dagger with Jack. I also saw that you use Retrolambda with java 8, is that really necessary? My suggestion is to follow the temporary solution proposed by this Issue of Dagger.

  • @Wakim removed the Retrolambda, but still the error occurs.

  • Hmm, removing Retrolambda does not actually solve the problem, it seemed to be just redundant given that it is using Java 8. It could include your project Gradle?

  • updated the question

  • My other suggestion would be to update your build tools to the version 2.3.0-beta3, and use Gradle 3.3 (just turn the command ./gradlew wrapper --gradle-version 3.3 to update).

  • I did, but the Kinvey, Calligraphy and Appcompat libraries that were being used are not being found .

Show 1 more comment

1 answer

1


Following the gk5885 response, updated Guava. In my case, I had to delete the guava-18.0.jar of the briefcase lib required by Kinvey for Dagger to automatically add the most compatible version.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.