4

I'm using Androidstudio 0.8.9 and build with gradle.

I was using Android-Annotations and works well. And I want use AspectJ also, so apply plugin(https://github.com/uPhyca/gradle-android-aspectj-plugin).

But compile fail, and throw some error message

:app:compileDebugJava
Internal compiler error: java.lang.IllegalStateException: java.lang.IllegalArgumentException: Unknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183)
:app:compileDebugAspectj FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugAspectj'.
> Internal compiler error: java.lang.IllegalStateException: java.lang.IllegalArgumentException: Unknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183)

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

BUILD FAILED

Total time: 13.616 secs
Unknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183)
2:04:32: External task execution finished 'build'.

My build.gradle is

repositories {
    mavenCentral()
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
        classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.+'
    }
}

def androidAnnotationsVersion = '3.1';
def daggerVersion = '1.0.0';

apply plugin: 'com.android.application'
apply plugin: 'android-aspectj'
apply plugin: 'android-apt'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.flask.aspectjtest"
        minSdkVersion 16
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
}

configurations {
    apt
    ajc
    aspects
    ajInpath
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName "com.flask.aspectjtest"
    }
}

ext.aspectjVersion = '1.8.2'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'

    apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
    compile "com.squareup.dagger:dagger:${daggerVersion}"
}

So, I tested aspectj plugin work alone(without android-annotations), and works well. And I find some answer (Android Annotations and MonkeyTalk?), FAQ Page of AA. But it was eclipse solution I think, and I can't solve my problem with this answer.

I changed annotation processor android-apt to ajc. But now, It can't find AndroidManifest.xml file. (because apt configuration is not available)

repositories {
    mavenCentral()
    maven { url 'http://repo.spring.io/snapshot' }
}

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
        classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.+'
    }
}

def androidAnnotationsVersion = '3.1';
def daggerVersion = '1.2.2';

apply plugin: 'com.android.application'
apply plugin: 'android-aspectj'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.flask.aspectjtest"
        minSdkVersion 16
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'build/generated/source/apt/${variant.dirName}']
            resources.srcDirs = ['src/main/resources']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
    }
}

configurations {
    ajc
    aspects
    ajInpath
}

ext.aspectjVersion = '1.8.2'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'

    ajc "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    ajc "com.squareup.dagger:dagger-compiler:${daggerVersion}"
    compile "com.squareup.dagger:dagger:${daggerVersion}"
}

Now,


:app:generateDebugSources UP-TO-DATE
Note: Resolve log file to /Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/androidannotations.log
Note: Initialize AndroidAnnotations 3.1 with options {}
Note: Start processing for 2 annotations on 13 elements
error: Could not find the AndroidManifest.xml file, going up from path [/Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug] found using dummy file [] (max atempts: file:///Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug/dummy1412644771646)
Note: Time measurements: [Whole Processing = 10 ms], [Extract Annotations = 7 ms], [Extract Manifest = 2 ms], 
Note: Finish processing
Note: Start processing for 0 annotations on 0 elements
Note: Time measurements: [Whole Processing = 0 ms], 
Note: Finish processing
1 error
:app:compileDebugJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

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

BUILD FAILED

Total time: 3.596 secs
Compilation failed; see the compiler error output for details.
10:19:31: External task execution finished 'build'.

androidannotations.log is below.


10:17:30.890 [Daemon Thread 2] INFO  o.a.AndroidAnnotationProcessor:84 - Initialize AndroidAnnotations 3.1 with options {}
10:17:31.58 [Daemon Thread 2] INFO  o.a.AndroidAnnotationProcessor:108 - Start processing for 2 annotations on 13 elements
10:17:31.77 [Daemon Thread 2] ERROR o.a.h.AndroidManifestFinder:134 - Could not find the AndroidManifest.xml file, going up from path [/Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug] found using dummy file [] (max atempts: file:///Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug/dummy1412644651076)
10:17:31.78 [Daemon Thread 2] INFO  o.a.p.TimeStats:81 - Time measurements: [Whole Processing = 19 ms], [Extract Annotations = 15 ms], [Extract Manifest = 2 ms],
10:17:31.78 [Daemon Thread 2] INFO  o.a.AndroidAnnotationProcessor:122 - Finish processing
10:19:31.568 [Daemon Thread 3] INFO  o.a.AndroidAnnotationProcessor:84 - Initialize AndroidAnnotations 3.1 with options {}
10:19:31.637 [Daemon Thread 3] INFO  o.a.AndroidAnnotationProcessor:108 - Start processing for 2 annotations on 13 elements
10:19:31.647 [Daemon Thread 3] ERROR o.a.h.AndroidManifestFinder:134 - Could not find the AndroidManifest.xml file, going up from path [/Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug] found using dummy file [] (max atempts: file:///Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug/dummy1412644771646)
10:19:31.648 [Daemon Thread 3] INFO  o.a.p.TimeStats:81 - Time measurements: [Whole Processing = 10 ms], [Extract Annotations = 7 ms], [Extract Manifest = 2 ms],
10:19:31.648 [Daemon Thread 3] INFO  o.a.AndroidAnnotationProcessor:122 - Finish processing

Community
  • 1
  • 1
Flask_KR
  • 269
  • 1
  • 6
  • 14
  • I suspect there is a conflict between aspectj-plugin and android-apt. Try to replace AA with any other annotation processor (like dagger). Does it still cause to same problem? – WonderCsabo Oct 05 '14 at 17:41
  • How can I replace annotation processor? – Flask_KR Oct 06 '14 at 05:59
  • 1
    I see you already have `dagger`. Just remove the two AA lines from the `dependencies` section. – WonderCsabo Oct 06 '14 at 10:42
  • But I want to use both library. Is it impossible? So that, Is there any library that feature like AA? (I think `SOURCE_OUTPUT` is default string of source output path config. If I change this configuration, compile may success?) – Flask_KR Oct 06 '14 at 14:20
  • You misunderstood me. My point is, not the "libraries" (processors like AA and dagger) conflict, but the android-apt plugin itself conflicts with the aspectj plugin. That's why i said to try it with just one processor. – WonderCsabo Oct 06 '14 at 14:51
  • Oh, sorry. I changed my annotation processor `android-apt` to `ajc`. But now, it cant' find AndroidManifest.xml file. Before, `android-apt` was can set some argument of that. But `ajc` doesn't have. – Flask_KR Oct 07 '14 at 01:27
  • I do not understand. `android-apt` is not an annotation processor, it is a plugin which can add annotation processor to the `gradle` classpath. You did completely wrong, since `ajc` is not an annotation processor plugin, but a plugin which can add `AspectJ` libraries to the classpath. So, does it work with [this](https://gist.github.com/WonderCsabo/c9f6b33efebd2aec0973) build script? – WonderCsabo Oct 07 '14 at 07:49
  • Thanks, but if I apply your `build.gradle`, `AndroidAnnotations` lib doesn't work any more. I want to use both library `AndroidAnnotations` and `AspectJ` in same project. Your build.gradle doesn't have `AndroidAnnotations` library so that I can't use `AndroidAnnotations` features. – Flask_KR Oct 08 '14 at 06:04
  • I know. I removed AA to check out whose fault is the problem above. So i suggest to remove things and add them back incrementaly, to see what causes the problem. – WonderCsabo Oct 08 '14 at 07:26
  • Oh, ok. Remove all AA features and apply your `build.gradle` build successful. No error occur and I can use `AspectJ`. [edited] And I got error when I add `compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"` in `dependencies` section. – Flask_KR Oct 08 '14 at 08:41
  • 1
    Please note you should add `androidannotations` as `apt` scope, and `androidannotations-api` with `compile` scope. – WonderCsabo Oct 08 '14 at 09:37
  • OMG.. It works perfectly as I expected! Thank you! I was stupid.. – Flask_KR Oct 09 '14 at 08:18
  • It is interesting, because in your first script, you added the scopes correctly. What else changed? :) – WonderCsabo Oct 09 '14 at 16:06
  • `compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"` was wrong, `compile "org.androidannotations:androidannotations-api:${androidAnnotationsVersion}"` is correct.(`-api` was required) But now, `AspectJ` could not find AA's generated classes. I add the issue to `gradle-android-aspectj-plugin`. Thanks anyway – Flask_KR Oct 10 '14 at 05:12
  • @Flask_KR did you achieve Dagger + aspectj plugin integration? – Aritz Feb 16 '15 at 16:59
  • @XtremeBiker unfortunately not yet. I gave up. I will try later. I just using AA with Dager. – Flask_KR Feb 24 '15 at 04:01

1 Answers1

1

Instead of AspectJ plugin - com.uphyca.gradle:gradle-android-aspectj-plugin' try to use https://github.com/Archinamon/GradleAspectJ-Android for dagger+aspectj plugin integration.

First add a maven repo link into your repositories block of module build file:

maven { url 'https://github.com/Archinamon/GradleAspectJ-Android/raw/master' }

Add the plugin to your buildscript's dependencies section:

classpath 'com.archinamon:AspectJ-gradle:1.0.15'

Apply the aspectj plugin:

apply plugin: 'com.archinamon.aspectj'

Now build your project and run.

  • its is not working, giving error thisError:Could not find org.fxclub.aspectj:AspectJ-gradle:1.0.15. – Syed Raza Mehdi Jul 28 '15 at 10:02
  • classpath and plugin name got changed.. I updated the steps above.. please try now. – umesh singh Jul 29 '15 at 07:47
  • @umeshsingh - thank you for your answer. I am having problems using yours or uPhyca's aspectj weaving plugins with my multi-flavoured project. Would you be able to advise on the problem I have raised with uPhyca's issue tracker (same affects your library); https://github.com/uPhyca/gradle-android-aspectj-plugin/issues/27 – BrantApps Aug 02 '15 at 13:03