0

I have modularised some simple classes into their own project for reuse elsewhere. These classes typically contain only fields and accessor methods (i.e. nothing Android specific).

They are later packaged up using ant's jar task and stored in a Maven repository.

In an Android project, I've stored said jar file into a libs directory and added to the build path. On running the emulator however, I get a "class not found" exception relating to my package. Other third party libraries (such as GSon) are being picked up fine.

Are there any specific steps required to make a jar file compatible with Android? (This reply seems to suggest otherwise). How can I debug this further?

Community
  • 1
  • 1
tlvince
  • 516
  • 3
  • 10

3 Answers3

0

No as long as you do not need e.g. classes from javax.* that are not in Android. If I were you I would consider looking at using the Android Maven Plugin for your build though. Check out the morseflash example from the official samples collection. It showcases exactly your scenario.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
0

You only need an Android library project if your going to be reusing Android components and resources. In your case, I believe you added the project to the build path, but I'm sure your not exporting it as part of the dependent project.

So open the project properties, open up the Java Build Path options and make sure that you have your JAR selected as an exported dependency in the Order and Export tab.

UPDATE

This is what your entry should read:

 <classpathentry exported="true" kind="lib" path="libs/tlvince-dao-0.1.0.jar"/>

I've also forked an updated version of your gist.

Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114
  • Could you add a gist of your project's *.classpath* file so we can debug? – Filip Dupanović Dec 16 '11 at 19:05
  • I tried with and without `exported="true"` still to no avail :( As mentioned previously, `GSon`, with same `classpathentry` *works*, which leads me to believe there is a discrepancy in the `jar` – tlvince Dec 17 '11 at 17:18
0

This issue was a result of compiling the jar to Java 7. Android does not support Java 7 (yet).

Compiling to Java 6 bytecode by setting target="1.6" in ant's javac task solved the issue.

Community
  • 1
  • 1
tlvince
  • 516
  • 3
  • 10