How to publish a library with static resources--android Chapter

Source: Internet
Author: User

1. First use the command-line tools provided by the Android SDK to work with existing projects:

1 CD Yourprojectdir 2 android update project-p./

2. In the build.xml generated in the previous step, there will be a reference to Custom_rules.xml, which is optional and does not affect compilation without custom_rules.xml. However, this file is exactly used to add a custom compilation step, and to add the assets resource to the jar package, create the file. After you create custom_rules.xml in the project catalog, add the following to it:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Projectname= "Custom_rules">3     <Targetname= "-post-compile"if= "${project.is.library}">4         <Echo>Post compile:add assests from ${asset.absolute.dir} to ${out.library.jar.file}</Echo>5         <JarDestFile= "${out.library.jar.file}"Update= "true">6             <Zipfilesetdir= "${asset.absolute.dir}"prefix= "Assets"excludes= "**/*.java ${android.package.excludes}"/>7         </Jar>8         <Echo>Post Compile:rename ${out.library.jar.file} to ${out.absolute.dir}/${standalone.jar.file}.jar</Echo>9         <Deletefile= "${out.absolute.dir}/${standalone.jar.file}.jar"Quiet= "true"/>Ten         <Renamesrc= "${out.library.jar.file}"dest= "${out.absolute.dir}/${standalone.jar.file}.jar"/> One     </Target> A </Project>

Where Standalone.jar.file is a configuration defined in Local.properties that represents the name of the jar package that you want to generate, and of course you don't have to write it anywhere else. What this code does is to make a jar package after compile and compress the files in the assets directory into the assets directory of the jar package. Then remove the old version of the jar package and change the newly generated jar package to the name we want. This will include assets resources in the jar package, and the APK can be referenced directly. In order not to generate a naming conflict, it is recommended that the assets resources in the jar package be placed in a subdirectory named after the library name so that the resources in the apk do not conflict with the resources in the library.

3. In order to use Eclipse debugging, we also need to configure Eclipse Engineering (the project on hand is temporarily not easy to switch to Android Studio, and later), implementation calls Ant automatic compilation. First of all, your PATH environment variable must have ant,windows platform recommended to install WINANT,MAC platform directly install Ant. You then configure eclipse to automatically invoke the effects of the ant compilation every time the original file is modified. The specific method is to click Project->properties, select Builders, add a builder, configure. Then all the default builder is not selected, just tick the newly added builder.

Note that the premise of this approach is that my project is not big, automatic compilation can keep up with the changes, if it is a large project, or do not automatically compile.

How to publish a library with static resources--android Chapter

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.