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开发者_JAVA技巧 project from the command line
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.
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.
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).
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.
Solution:
- right click on the project in project tree and select Project properties
- select Java Build Path
- select TAB Order and Export
- check GoogleAdMobAdsSdk-4.0.4.jar (or your version SDK)
- press OK
- clean project by menu Project -> Clean
- rebuild project (Project – Build Automatically)
精彩评论