Книга: Beginning Android

Ants and JARs

Ants and JARs

You have two choices for integrating third-party code into your project: use source code or use pre-packaged JARs.

If you choose to use the third-party source code, all you need to do is copy it into your own source tree (under src/ in your project) so it can sit alongside your existing code, then let the compiler perform its magic.

If you choose to use an existing JAR, perhaps one for which you do not have the source code, you will need to teach your build chain how to use the JAR. If you are using an IDE, that’s a matter of telling it to reference the JAR. If, on the other hand, you are not using an IDE and are relying upon the build.xml Ant script, put the JAR in the libs/ directory created for you by activityCreator, and the Ant build process will pick it up.

For example, in a previous draft of this book, we had a MailBuzz project. MailBuzz, as the name suggests, dealt with email. It leveraged the JavaMail APIs and needed two JavaMail JARs: mail-1.4.jar and activation-1.1.jar. With both of those in the libs/ directory, the classpath told javac to link against those JARs, so any JavaMail references in the MailBuzz code could be correctly resolved. Then, those JARs were listed, along with the MailBuzz compiled classes, in the task that invokes the dex tool to convert the Java code into Dalvik VM instructions. Without this step, even though your code may compile, it won’t find the JavaMail classes at runtime and will fail with an exception.

As it turned out, though, the Dalvik VM and compiler supplied with the Android 0.9 and newer SDKs no longer supported some Java language features used by JavaMail. And, while the JavaMail source code is available, it is under an open-source license (Common Development and Distribution License; CDDL) that… has issues.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.374. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз