2

I am building a library for use in Android apps. So far I have been using a library project in Eclipse to make a jar file. That works fine, but I'd like to build the jar from source using a command-line invocation of some sort. Yesterday I tried doing something along the lines of:

javac -d bin/classes -classpath\
    my-android-sdk/platforms/android-19/android.jar\
    com/mycompany/mystuff.java ...

jar cf mystuff.jar -C bin/classes com

This generates a jar alright, but I've had no luck using that jar in an Android Eclipse project. I get runtime errors of the form "unable to resolve static method...".

Should this work? Is there a better way to build an android-project-compatable jar at the command-line?

Thanks in advanced.

Edit: Following the advice of CommonsWare, I found I can build the jar by replacing javac above with ant. First I use Eclipse to export a build.xml file (https://stackoverflow.com/a/4186557) then I appeal to ant at the command-line to generate bin/classes. Then I build the jar from the command-line like before. I still don't know why javac doesn't produce the same thing, but this is good enough for me.

Community
  • 1
  • 1
2-complex
  • 333
  • 3
  • 11
  • How are you attempting to use the JAR? IOW, what did you do on the Eclipse side to use this JAR? – CommonsWare Dec 04 '13 at 21:05
  • I copy the jar into the libs/ directory of an Eclipse project, and then, in the source of that project, I import classes from the jar and use them. If I make the jar in Eclipse, that seems to be enough. One complicating factor is that I'm going to want to appeal to the jar via JNI, but I figure that's step 2. For now, the jar I built using the command-line is not even amenable to java-only. – 2-complex Dec 05 '13 at 22:55
  • UnZIP the contents of both JARs (made in Eclipse and made via **`jar`**) and see what is different. – CommonsWare Dec 05 '13 at 23:28
  • Both unzipped jars contain directories in a structure appropriately mimicking the package name. The .class files in each have the same names, but they differ in content. For one thing, they are slightly different sizes. I decompiled two .class files and diffed the results. The decompiled files are identical except for the names of local variables and function arguments. The eclipse version remembers the original names, the names in the other file are generic. Also, the manifest generated by jar is the default one, the one generated by eclipse is blank. – 2-complex Dec 07 '13 at 02:20
  • :: shrug :: I haven't built a JAR by hand in *ages*. I build JARs with Ant (and now Gradle) all the time for my Android CWAC projects, without issue. – CommonsWare Dec 07 '13 at 13:04
  • Perhaps I will look into using one of those tools; I don't need this to work with javac and jar, anything I can run from the command-line will do. Thanks for your help. – 2-complex Dec 10 '13 at 22:15

0 Answers0