Android Class Library packaging, publishing methods

Source: Internet
Author: User

When developing Android apps, how do you package this part into a class library for a common part that can be used for multiple applications, or the part that you plan to publish to a third party for application integration?
Android apps using ADT to package into apk,apk contain everything you need to run the program, including: class, asset, Res, androidmanifest.xml, and so on. In the case of the Library project, ADT generates a JAR package containing only the compiled class file, not the Res resource file, and the res only enters the APK package when the app package apk is packaged.

What about the self-exporting jar? Export the res for the class Library project (the Library project), which is checked when exporting, so the exported jar package does contain the resource file under Res. Unfortunately, it has been repeatedly tested that even if the jar contains res, the target application project will still not process the res in the jar package at compile time, and the res in the jar will not be included when the APK package is hit. This way, the path through which the RES is included in the jar package for use by the target application project is out of order.

Let's make a summary:
1. The Android Library project can be packaged as a jar, and the bytecode class file in the jar can be successfully entered into the APK package of the target application project. If the class library does not contain content that requires interface resources such as activity, or if the resource is read manually in the class library, instead of using ADT's mechanism to read resources from the RES, the use of this class library jar is completely fine and does not require special attention.
2. The resource file under Res does not make sense in the jar package, the target app will not read the res from the jar when the APK package is hit apk. The possible reason to guess that the res is not supported for reading from the jar is to worry about duplication of resource names and target application items (purely personal guesses).

Can not play jar package, directly to the source code out and inappropriate, how to do?

Here's one way:
1. Development of the Library project (library project, Android---Project, Properties, Check "is Library"), compile normally, generate jar package (under Bin, only package in jar The byte code generated by the class with SRC does not contain Gen-generated classes or res. Assuming this class library is called Mylib, the generated jar name is called Mylib.jar.
2. Create a new Class Library project (library project, also set up project--Properties, Android--Check "is library"), assuming this class library is called Mylibdepl Oy, set its namespace to be the same as mylib. Create a new Libs directory under Mylibdeploy and import the Mylib.jar into the Libs directory. Then copy the assets and RES directories under the Mylib project to Mylibdeploy.
3. Develop target applications (general Android project, do not tick "is Library"), set a reference to Mylibdeploy in this target application project. Here's how: Open Android App Settings Project--Properties--Android, click the "Add ..." button to select Mylibdeploy. Once this is set, the classes in Mylib can be referenced in the target application project.

4. Finally compiled and exported to APK, this apk will contain the res under Mylibdeploy, and will also contain the corresponding Gen automatically generated class compiled files.

For class libraries that need to be published out, the Mylibdeploy is sent directly. It can be compressed into a zip or other format, as long as the user can solve the line. The user (target application developer) refers to the Mylibdeploy in the 3rd step, the normal use of Mylib.jar, the normal package apk.

Of course, when packaging jars (Mylib.jar in the example above), you can partially confuse them as needed to produce jar packages that are not easily deserialized.

This is not a perfect way to release packages, expect ADT to improve, and may be able to publish the jar directly in the future.

Reference:
[1]. Managing Projects from Eclipse with ADT
Http://developer.android.com/tools/projects/projects-eclipse.html

[2]. Android Developer Tools
Http://developer.android.com/tools/help/adt.html

[3]. How to export the project as a JAR file
http://groups.google.com/group/android-developers/browse_thread/thread/bc4b509765bd1956

[4]. How to create an Android library in Eclipse?
Http://groups.google.com/group/android-developers/browse_thread/thread/ce546a393cbb8bcf

[5]. Research on the packaging method of Android class library

Http://www.cnblogs.com/wangchuanju/articles/android_lib_jar.html

Android Class Library packaging, publishing methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.