Java library depending on Android library

70 views
Skip to first unread message

Roman Mazur

unread,
Feb 15, 2014, 5:41:21 AM2/15/14
to adt...@googlegroups.com
I understand that making a plain Java library that depends on Android one is not usually a good thing and actually does not make sense.
But what if I want to add some annotation processor to my Android library?

As far as I understand these processors should be packed in a separate jar that can be added to a provided configuration in an app project.

I suppose if I organized processors project as an Android library and packed it in aar, it still could be linked in 'provided' configuration and processors would be discoverable for javac.
But I believe you will agree that annotation processor tests should be run on the host system, and I won't be feeling very comfortable while developing processors as an android lib.

Thus my current choice is to have a plain Java project for annotation processor which depends on an Android library (actually on its dedicated configuration producing a jar).
This gives me a way to write code and run tests rather comfortably.

So my Android library has a configuration 'plain' and there is a declared artifact with classes jar for this configuration.
Java project depends on it:
compile project(path: ':android-lib', configuration: 'plain')

But there is a sample Android app which currently cannot do

provided project(':java-project-with-annotation-processors')

because I'm getting

"My Java Project" depends on libraries but is not a library itself
at BasePlugin.addDependency(BasePlugin.groovy:2073)

Here is where I'm doing my experiments: https://github.com/stanfy/enroscar/tree/goro-2/goro

Any thoughts appreciated. Thanks.

Jürgen Cruz

unread,
Feb 16, 2014, 10:48:19 AM2/16/14
to adt...@googlegroups.com
Isn't there a way to split or abstract out your android library so that it becomes one Java library from which your preprocessor and android library and eventually your app depend on?
Reply all
Reply to author
Forward
0 new messages