title: Is it possible to integrate Dagger and AspectJ in an Android Studio project?
body: <p>I'm working in an Android project where I'm using Dagger for dependency injection. I don't know so much about Gradle, but as far as I understand, the Dagger annotations are processed by its compiler once the project is built. There's no problem in configuring it as the user guide says. Well, now I want to integrate AspectJ too, so I'm looking at <a href="https://github.com/uPhyca/gradle-android-aspectj-plugin" rel="nofollow noreferrer">one of the plugins for Android</a>.</p>
  
  <p>However, it seems this plugin does a build post processing job to read the aspects too, which remains in conflict with what Dagger compiler does. That's my current <em>build.gradle</em> file (Built a test project to have a <a href="http://sscce.org/" rel="nofollow noreferrer">SSCCE</a>):</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  buildscript {
      repositories {
          mavenLocal()
          mavenCentral()
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:1.0.0'
          classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.9'
      }
  }
  
  apply plugin: 'android-aspectj'
  
  android {
      compileSdkVersion 20
      buildToolsVersion "20"
  
      defaultConfig {
          minSdkVersion 12
          targetSdkVersion 20
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:support-v4:20.+'
      compile 'com.android.support:appcompat-v7:20.+'
      compile 'com.squareup.dagger:dagger:1.2.2'
      provided 'com.squareup.dagger:dagger-compiler:1.2.2'
  }
  </code></pre>
  
  <p>And the Aspect used:</p>
  
  <pre><code>@Aspect
  public class HelloAspect {
      @Around("execution(void com.mycompany.test.MainActivity.test())")
      public void around(ProceedingJoinPoint pj) throws Throwable {
          Log.d("Prueba","Hello, @Aspect");
      }
  }
  </code></pre>
  
  <p>And that's the exception being thrown:</p>
  
  <pre><code>java.lang.RuntimeException: 
  Problem processing attributes in C:\Users\user1\workspaces\android\Test\app\build\intermediates\classes\debug\tesicnor\com\test\aspects\HelloAspect.class
  at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:387)
  at org.aspectj.weaver.bcel.BcelObjectType.&lt;init&gt;(BcelObjectType.java:162)
  at org.aspectj.weaver.bcel.BcelWorld.buildBcelDelegate(BcelWorld.java:410)
  at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:490)
  at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:456)
  at org.aspectj.weaver.bcel.BcelWeaver.addClassFile(BcelWeaver.java:453)
  at org.aspectj.weaver.bcel.BcelWeaver.addClassFile(BcelWeaver.java:477)
  at org.aspectj.ajdt.internal.core.builder.AjBuildManager.initBcelWorld(AjBuildManager.java:904)
  at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:249)
  at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185)
  at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
  at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
  at org.aspectj.tools.ajc.Main.run(Main.java:371)
  at org.aspectj.tools.ajc.Main$run.call(Unknown Source)
  at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
  at com.uphyca.gradle.android.AspectjCompile.compile(AspectjCompile.groovy:63)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
  at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579)
  at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
  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:64)
  at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
  at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
  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.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
  at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
  at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
  at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
  at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
  at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
  at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
  at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
  at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
  at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
  at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
  at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
  at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
  at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:43)
  at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30)
  at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:119)
  at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
  at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
  at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
  at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
  at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
  at org.gradle.util.Swapper.swap(Swapper.java:38)
  at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
  at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
  at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
  at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
  at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
  at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
  at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:745)
  
  Error:java.lang.RuntimeException: bad WeaverState.Kind: -115.  File was :&lt;Unknown&gt;::0
  at org.aspectj.weaver.WeaverStateInfo.read(WeaverStateInfo.java:170)
  at org.aspectj.weaver.AjAttribute.read(AjAttribute.java:105)
  at org.aspectj.weaver.bcel.Utility.readAjAttributes(Utility.java:101)
  at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:383)
  </code></pre>
  
  <p>It seems AspectJ can't weave <code>HelloAspect</code>'s attributes. In fact, it looks like the file itself can't be found (<code>File was :&lt;Unknown&gt;::0</code>). So... Can AspectJ be used with Dagger altogether? I have no problems when using them separately.</p>
  
  <p>My Test project in a <a href="https://www.dropbox.com/s/epvsf2qo4sf2bjx/Test.zip?dl=0" rel="nofollow noreferrer">zip file</a></p>
  
  <p><strong>Related:</strong></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/26199972/when-i-apply-aspectj-to-android-project-with-androidannotations-not-work">When I apply AspectJ to Android project with Androidannotations not work</a></li>
  </ul>