Rax
Rax

Reputation: 1567

Dagger build fails with realm plugin, Cannot find symbol class DaggerApplicationComponent

While setting up realm in project by following this documentation.

below is my project level gradle :

buildscript {
repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    // Realm
    classpath "io.realm:realm-gradle-plugin:1.2.0"
}

app level gradle :

apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

dependencies {
 final DAGGER_VERSION = '2.7'
....
    def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
    annotationProcessor daggerCompiler
    testAnnotationProcessor daggerCompiler
    androidTestAnnotationProcessor daggerCompiler

    compile  "com.google.dagger:dagger:$DAGGER_VERSION"
    provided 'org.glassfish:javax.annotation:10.0-b28' //Required by Dagger2


}

Upvotes: 3

Views: 967

Answers (2)

jeremy303
jeremy303

Reputation: 9241

This answer is based off of Vasiliy's previous answer. I'm promoting my comments to his/her answer to make the solution that worked for me more visible.

As Vasiliy suggested, reversing these lines:

apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

to

apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'

allowed the reporting of an underlying Realm error that was preventing Dagger from generating my application component class (in my case, a breaking change introduced in Realm 2.x).

After addressing this issue, with the reordered apply plugin lines I received this error:

java.lang.IllegalArgumentException: XXX is not part of the schema for this Realm

By reordering the plugins, Realm annotations are not being processed as needed. So the plugin lines must then be restored to:

apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

Upvotes: 0

Vasiliy
Vasiliy

Reputation: 16228

This is one of the most serious downsides of Dagger 2 - its error reporting is terrible. I regularly observe these kind of errors, and you can't understand a thing from that message.

The problem is that Dagger 2 pre-processor runs before javac compilation, and if the code couldn't be processed, then pre-processor fails without generating components implementations. To my best knowledge, the pre-processor doesn't report what error caused the failure. Then, when javac compilation executed it fails because it can't find the generated file, but it doesn't proceed to compilation of other files, therefore the only error you see is about missing Dagger component.

What I do in such cases is three stepped solution:

  1. Review VCS history and visit all changed files. Since IDE compiles each file upon visit, I will see if any of them has compilation errors.
  2. If #1 didn't help, I would try to incrementally remove Dagger 2 code from the project (commit beforehand!) and try to recompile on the way. When Dagger 2 is removed from problematic region, Dagger components will be generated and javac comilation will show you the actual errors.
  3. If nothing else helps, I'm visiting all project files one-by-one. Have done it twice already, and it is a nightmare.

I know nothing about Realm, but since I see it uses its own plugin, you could start by changing the order of plugins appliance in build.gradle. Switch these lines:

apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

Upvotes: 2

Related Questions