4

I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.

I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:

ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView

my build.properties looks like this:

jar.libs.dir=libs

And the libs/ directory contains my .jar file.

What needs to be in build.xml so that the external .jar file is included in the APK?

Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line

Community
  • 1
  • 1
poundifdef
  • 18,726
  • 23
  • 95
  • 134

5 Answers5

4

I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.

Hyndrix
  • 4,282
  • 7
  • 41
  • 82
1

It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:

Warning: Reference out.dex.jar.input.ref has not been set at runtime, but was found duringbuild file parsing, attempting to resolve. Future versions of Ant may support referencing ids defined in non-executed targets.

I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.

poundifdef
  • 18,726
  • 23
  • 95
  • 134
0

What needs to be in build.xml so that the external .jar file is included in the APK?

Just putting it in libs/ is sufficient.

my build.properties looks like this:

That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.

If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hm. So it must be something wonky with my build.xml, then; `dexdump -f classes.dex | grep -in adview` yields `3080: 0x0013 - 0x0040 reg=0 adView Lcom/google/ads/AdView;` – poundifdef Jul 23 '11 at 15:53
  • Though my build.xml is basically the default auto-generated one, – poundifdef Jul 23 '11 at 15:59
  • @poundifdef: No, since you see the class in the dexdump output, that means the class should be in the APK file (you can confirm this by unzipping the APK and checking `classes.dex` from in there, but it should be the same AFAIK). Hence, either you're missing a dependent JAR or there's something strange about how you are trying to create that `AdView` (e.g., using a custom classloader). – CommonsWare Jul 23 '11 at 16:09
0

You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.

Dmitriy R
  • 613
  • 1
  • 5
  • 12
0

Solution:

  1. right click on the project in project tree and select Project properties
  2. select Java Build Path
  3. select TAB Order and Export
  4. check GoogleAdMobAdsSdk-4.0.4.jar (or your version SDK)
  5. press OK
  6. clean project by menu Project -> Clean
  7. rebuild project (Project – Build Automatically)
EdChum
  • 376,765
  • 198
  • 813
  • 562
  • Hi; thanks for this answer! However, this pertains to using eclipse, and I was asking how to do it *without* eclipse! – poundifdef Mar 28 '12 at 17:26