9

I have some java code (compiles nicely for Android) in a library project (LIB) that I want to use in an another Android project (A).

As LIB's code is unlikely to change much, I opted for adding it as a jar to A. It works fine.

I have another project that is an Android instrumentation project, testing the first Android project (B).

So what we have now is A including LIB as an external jar, and B testing A.

The problem starts when I want to access from B code written in LIB. From what I see, unless I add LIB as an external jar to B, it refuses to compile (that is, it cannot access the code in the LIB jar that is included in A).

I am reluctant to add LIB as an external jar to B because: 1. It doesn't feel right, and 2. When running the tests it fails with:

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

I found Mike's question, but his solution only covers compiling using an ant script, and I currently prefer to use the Eclipse IDE for this project.

Any idea how can I solve this issue?

Community
  • 1
  • 1
Amit Kotlovski
  • 1,848
  • 1
  • 18
  • 13
  • 2
    Solved by following [This blog post](http://dtmilano.blogspot.com/2009/12/android-testing-external-libraries.html). It seems that I should have _exported_ LIB from A, to make it accessible from B. – Amit Kotlovski Oct 12 '10 at 12:21
  • That helped. I exported the android dependencies from the main project (the jar was in libs folder, so it was not possible to export it directly), and in the test project also had to check the main project. Now it works. – User May 06 '12 at 18:57

1 Answers1

1

(In order to remove this question from the "Unanswered" filter...)

The solution is outlined here:

Android Testing: External libraries

The LIB should be exported from A to make it accessible from B.

DreadPirateShawn
  • 8,164
  • 4
  • 49
  • 71
  • I originally answered my question, but my answer got converted into a comment by someone in the StackOverflow system, providing my with a link to the faq. I guess the message was that my answer doesn't constitue a proper answer, as it is mostly a reference to the external link. – Amit Kotlovski Jan 20 '13 at 15:50
  • Hmm. Fair enough. I understand their logic, but only if the system also allowed such questions to be removed from the "Unanswered" filter at the same time. Otherwise it's left in limbo forever. :-/ – DreadPirateShawn Jan 20 '13 at 20:02