0

I am writing an Android library that I plan to use with different projects. There is also an annotation processor library that I am writing that would be used to generate code based on annotation defined in the previous library.

The project structure is:

Project
    -> app (the test app)
    -> Android Library
    -> Annotation Processor

My android library depends on appcompat and support:design libraries. Build.gradle for it is:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile files('libs/guava-18.0.jar')
}

And build.gradle for annotation processor is:

apply plugin: 'java'

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java']
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(":lib")
}

The issue here is when I build the project it gives me following error:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':threepio-anno-proc:compile'.
        > Could not find com.android.support:appcompat-v7:22.2.0.
        Searched in the following locations:
        https://jcenter.bintray.com/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.pom
https://jcenter.bintray.com/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.jar
Required by:
Threepio:threepio-anno-proc:unspecified > Threepio:lib:unspecified
> Could not find com.android.support:design:22.2.0.
        Searched in the following locations:
        https://jcenter.bintray.com/com/android/support/design/22.2.0/design-22.2.0.pom
https://jcenter.bintray.com/com/android/support/design/22.2.0/design-22.2.0.jar
Required by:
Threepio:threepio-anno-proc:unspecified > Threepio:lib:unspecified

It compiles if dependency of android library is removed from annotation processor module. That means android library project is able to access support and design packages but not annotation processor.

Abdullah
  • 7,143
  • 6
  • 25
  • 41
  • I assume your android sdk is up-to-date? – stkent Jul 14 '15 at 00:55
  • Yes android sdk is up-to-date. – Abdullah Jul 14 '15 at 05:45
  • Your annotation processing module cannot depend on android modules. The java plugin used to compile the annotation processor module is incompatible with the android plugin. And as you see in the error messages the support libraries are not accesible to the annotation processor since they are in fact not hosted anywhere on a public maven repository. You download the support libraries through the SDK manager into a local maven repository which is then subsequently used by the andorid plugin the satisfy the dependencies. A java module can't do that so easily. – Xaver Kapeller Jul 20 '15 at 08:56
  • Or to summarize: You can't do that. You cannot have a java module which depends on an android module. And that definition include annotation processors. – Xaver Kapeller Jul 20 '15 at 08:57
  • In that case I can not reference the annotation that I have defined in android library module. I created a simple java module to declare my annotations that is reference by both the android library module and annotation processor. Yesterday I checked out you EasyAdapter project from which I got another technique to accomplish what I need. Thanks for your help. – Abdullah Jul 20 '15 at 14:40

0 Answers0