realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.46k stars 1.75k forks source link

gradle assemble fails with Dagger2 2.6 #3344

Closed ghost closed 8 years ago

ghost commented 8 years ago

Goal

Successful builds with dagger2 2.6

Expected Results

gradle assembleDevelopmentDebug completes without exception

Actual Results

FAILURE: Build failed with an exception.

include the following buildscript dependencies :

        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath "io.realm:realm-gradle-plugin:1.2.0"

apply the following plugins to project:

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

include dagger:

    compile "com.google.dagger:dagger:$daggerVersion"
    apt "com.google.dagger:dagger-compiler:$daggerVersion"

The issue has already been raised with the dagger team here: https://github.com/google/dagger/issues/446

The solution is to explicitly include guava to apt

Code Sample

Version of Realm and tooling

Realm version(s): 11.1 and 1.2.0

Android Studio version: 2.1.3

Which Android version and device: N/A

Zhuinden commented 8 years ago

I don't think Realm uses Guava at all. An even more interesting fact is that just the other day, I compiled a project with Realm 1.2.0 and Dagger 2.6.

Not sure why this happens in your case. Do you have any other dependencies?

ghost commented 8 years ago

There's a lot of dependencies, but these are the only ones that are annotation processors. The app can build fine and run, but cannot assemble.

kneth commented 8 years ago

We released a minor change related to annotation processing in 1.1.1 (see #3216). @kdaypossible can you try to build with an older version? If you can, we might have to revisit #3216.

Zhuinden commented 8 years ago

@kneth I don't think this commit would somehow break Guava though.

Just a hunch that something more notorious and unrelated is going on here.

Can you try

classpath 'com.android.tools.build:gradle:2.1.2'

?

ghost commented 8 years ago

@kneth The error persists with realm plugin 1.1.0. @Zhuinden downgrading the plugin version requires downgrading the gradle version. I tested it with build tool 2.1.2 and gradle 2.10, and the build error is still there.

Zhuinden commented 8 years ago

Don't you by chance use ProducerModule and stuff? That also brings Guava in I think. I can see that causing issues.

ghost commented 8 years ago

@Zhuinden It's definitely dagger using guava. It's in the stack trace for the error. I just realized I forgot to mention databinding is enabled.

Here's the stacktrace:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':redacted:compileDevelopmentDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.append(Ljava/lang/Iterable;)Lcom/google/common/collect
/FluentIterable;

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':redacted:compileDevelopmentDebugJavaWithJavac'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:6
9)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter
.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.j
ava:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52
)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43
)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java
:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java
:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.jav
a:66)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:153)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:150)
        at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:92)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:
99)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:48)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:81)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:46)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)

        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:237)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.append(Ljava/lang
/Iterable;)Lcom/google/common/collect/FluentIterable;
        at com.sun.tools.javac.main.Main.compile(Main.java:553)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:46)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:
104)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
        at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
        at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
        at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:163)
        at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:145)
        at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:93)
        at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(Annotat
ionProcessingTaskFactory.java:245)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationPr
ocessingTaskFactory.java:221)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(Annotatio
nProcessingTaskFactory.java:232)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationPr
ocessingTaskFactory.java:210)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80
)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:6
1)
        ... 68 more
Caused by: java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.append(Ljava/lang/Iterable;)Lcom/google/commo
n/collect/FluentIterable;
        at dagger.internal.codegen.BindingGraph.componentRequirements(BindingGraph.java:135)
        at dagger.internal.codegen.AbstractComponentWriter.addBuilderFields(AbstractComponentWriter.java:316)
        at dagger.internal.codegen.AbstractComponentWriter.addBuilder(AbstractComponentWriter.java:294)
        at dagger.internal.codegen.AbstractComponentWriter.write(AbstractComponentWriter.java:261)
        at dagger.internal.codegen.ComponentGenerator.write(ComponentGenerator.java:72)
        at dagger.internal.codegen.ComponentGenerator.write(ComponentGenerator.java:35)
        at dagger.internal.codegen.SourceFileGenerator.generate(SourceFileGenerator.java:68)
        at dagger.internal.codegen.ComponentProcessingStep.generateComponent(ComponentProcessingStep.java:155)
        at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:142)
        at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:47)
        at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:318)
        at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:171)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        ... 88 more

BUILD FAILED

Here's the dependency graph for apt:

apt
+--- io.realm:realm-annotations:1.2.0
+--- io.realm:realm-annotations-processor:1.2.0
|    +--- com.squareup:javawriter:2.5.0
|    \--- io.realm:realm-annotations:1.2.0
+--- com.google.dagger:dagger-compiler:2.6
|    +--- com.google.dagger:dagger:2.6
|    |    \--- javax.inject:javax.inject:1
|    +--- com.google.dagger:dagger-producers:2.6
|    |    +--- com.google.dagger:dagger:2.6 (*)
|    |    \--- com.google.guava:guava:19.0
|    \--- com.google.guava:guava:19.0
+--- io.realm:realm-android-library:1.2.0
|    +--- io.realm:realm-annotations:1.2.0
|    \--- com.getkeepsafe.relinker:relinker:1.2.1
+--- com.android.support:support-v4:24.1.1
|    \--- com.android.support:support-annotations:24.1.1
+--- com.android.support:appcompat-v7:24.1.1
|    +--- com.android.support:animated-vector-drawable:24.1.1
|    |    \--- com.android.support:support-vector-drawable:24.1.1
|    |         \--- com.android.support:support-v4:24.1.1 (*)
|    +--- com.android.support:support-v4:24.1.1 (*)
|    \--- com.android.support:support-vector-drawable:24.1.1 (*)
+--- com.android.support:recyclerview-v7:24.1.1
|    +--- com.android.support:support-v4:24.1.1 (*)
|    \--- com.android.support:support-annotations:24.1.1
+--- com.android.support:cardview-v7:24.1.1
|    \--- com.android.support:support-annotations:24.1.1
+--- com.android.support:design:24.1.1
|    +--- com.android.support:support-v4:24.1.1 (*)
|    +--- com.android.support:recyclerview-v7:24.1.1 (*)
|    \--- com.android.support:appcompat-v7:24.1.1 (*)
+--- com.google.code.gson:gson:2.6.2 -> 2.7
+--- javax.annotation:jsr250-api:1.0
+--- com.jakewharton:butterknife:8.2.1
|    +--- com.jakewharton:butterknife-annotations:8.2.1
|    |    \--- com.android.support:support-annotations:24.0.0 -> 24.1.1
|    \--- com.android.support:support-annotations:24.0.0 -> 24.1.1
+--- com.jakewharton.timber:timber:4.1.1
+--- com.github.bumptech.glide:glide:3.7.0
+--- com.google.dagger:dagger:2.6 (*)
+--- project :exoplayer-amazon-port
+--- project :videoplayer-library
+--- project :videoplayer-library-exoplayer
+--- project :analytics-library-aspen
+--- project :ads-library-freewheel
+--- project :exoplayer-ext-okhttp
+--- com.squareup.okhttp3:okhttp:3.2.0 -> 3.3.0
|    \--- com.squareup.okio:okio:1.8.0
+--- com.squareup.okhttp3:logging-interceptor:3.2.0
|    \--- com.squareup.okhttp3:okhttp:3.2.0 -> 3.3.0 (*)
+--- com.squareup.retrofit2:retrofit:2.1.0
|    \--- com.squareup.okhttp3:okhttp:3.3.0 (*)
+--- com.squareup.retrofit2:converter-gson:2.1.0
|    +--- com.squareup.retrofit2:retrofit:2.1.0 (*)
|    \--- com.google.code.gson:gson:2.7
+--- com.squareup.retrofit2:converter-scalars:2.1.0
|    \--- com.squareup.retrofit2:retrofit:2.1.0 (*)
+--- com.squareup.retrofit2:converter-simplexml:2.1.0
|    +--- com.squareup.retrofit2:retrofit:2.1.0 (*)
|    \--- org.simpleframework:simple-xml:2.7.1
+--- com.squareup.retrofit2:adapter-rxjava:2.1.0
|    +--- com.squareup.retrofit2:retrofit:2.1.0 (*)
|    \--- io.reactivex:rxjava:1.1.5 -> 1.1.9
+--- uk.co.chrisjenx:calligraphy:2.2.0
|    \--- com.android.support:appcompat-v7:23.1.1 -> 24.1.1 (*)
+--- io.reactivex:rxjava:1.1.9
+--- io.reactivex:rxandroid:1.2.1
|    \--- io.reactivex:rxjava:1.1.6 -> 1.1.9
+--- com.android.databinding:library:1.1
|    +--- com.android.support:support-v4:21.0.3 -> 24.1.1 (*)
|    \--- com.android.databinding:baseLibrary:1.1 -> 2.1.3
+--- com.android.databinding:baseLibrary:2.1.3
+--- com.android.databinding:adapters:1.1
|    +--- com.android.databinding:library:1.1 (*)
|    \--- com.android.databinding:baseLibrary:1.1 -> 2.1.3
\--- com.android.databinding:compiler:2.1.3
     +--- com.android.databinding:baseLibrary:2.1.3
     \--- com.googlecode.juniversalchardet:juniversalchardet:1.0.3

(*) - dependencies omitted (listed previously)

BUILD SUCCESSFUL

And the dependencies for provided, since that's where I think databinding happens:

provided - Classpath for only compiling the main sources.
\--- com.android.databinding:compiler:2.1.3
     +--- com.android.databinding:baseLibrary:2.1.3
     \--- com.googlecode.juniversalchardet:juniversalchardet:1.0.3
Zhuinden commented 8 years ago

I found this issue here: https://code.google.com/p/android/issues/detail?id=205589

Apparently you can add guava to apt dependency and it will compile?

ghost commented 8 years ago

Yeah, that's the fix. I wanted to report this as a bug however, but it seems like it's actually not a realm issue. I'll ask the dagger team about it.

beeender commented 8 years ago

Since it doesn't seem to be a Realm issue, i am closing it. Feel free to reopen it! thanks!

rakshitsoni02 commented 8 years ago

facing same issue, My build fails after apply plugin: 'realm-android' in app level gradle file .

error: cannot find symbol class DaggerApplicationComponent any suggestions will be helpful .

Zhuinden commented 8 years ago

@rakshitsoni02 that means your Dagger configuration has some bugs. The build logs tend to specify what went wrong.