Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import an Android library and use it in both production code and tests?

I've extracted a bunch of functionality from my app into a library. The problem is I'd like to make use of the library classes in both production code and tests. The issue is that my app, my library, and the test code are separate modules, so both the app code and the test code need to depend on the library. When I try to compile the test module, I get the following error:

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: (some class)

It's cryptic, but it's trying to say that I've tried to add the same class to the .dex file more than once. It's not too surprising since the test code depends on the library code and on the app at compile time, which also depends on the library at compile time. How do I set up my dependencies (or change my code) to avoid this?

NOTE: I'm using IntelliJ IDEA 10.5 CE, so I use their terminology, but I think the problem is at least conceptually IDE-agnostic.

like image 396
Lyudmil Avatar asked May 27 '11 13:05

Lyudmil


1 Answers

It's a bug in IDEA, we've submitted an issue for it, please watch/vote.

like image 175
CrazyCoder Avatar answered Oct 22 '22 21:10

CrazyCoder