How to import the Android library and use it both in production code and in tests?

I extracted a bunch of functionality from my application to the library. The problem is that I would like to use library classes in both production code and tests. The problem is that my application, my library and test code are separate modules, therefore both the application code and the test code must depend on the library. When I try to compile a test module, I get the following error:

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

This is cryptic, but he is trying to say that I tried to add the same class to the .dex file more than once. This is not too surprising, since the test code depends on the library and application code at compile time, which also depends on the library at compile time. How to configure my dependencies (or change the code) to avoid this?

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

+6
source share
2 answers

This is a mistake in IDEA, we sent her a question, watch / vote .

+2
source

Hi, I feel that the same jar is added several times in different ways.

There are two ways to place jar in your project

 Right on Project->Properties->Java Build Path->Add Jars-> Right on Project->Properties->Java Build Path->Add External jars-> 

first remove all the cans. inside the folder of your application, create a folder in which all the necessary banks are placed.

 Right on Project->Properties->Java Build Path->Add Jars-> select your project folder and select the jar file 

Thanks Deepak

0
source

Source: https://habr.com/ru/post/889206/


All Articles