(Android) How to use a high-reusability project for other projects (jar export, import, is Library)

Source: Internet
Author: User

We have done a project, and the code in this project will often be used by other projects. For this highly reusable project (referred to as "Project 1") to be used by other projects (hereinafter referred to as "Project 2"), we currently have two methods to reduce the amount of code.

One approach is to package Project 1 as a jar file, export, import into Project 2, and call for Project 2.

Another way: Call Project 1 as the library for Project 2.

One, jar export, import

1.jar Export

Now there is a ready-made item 1

The function is erect seekbar

There's only one Verticalseekbar class, no activity and no resource files to pack.

Now we start packing:

(1) Right-click Project selection Export:

(2) Select the export target: Java->jar file:

(3) Check out some unnecessary documents, such as:

Generally, files that do not need to be penetrated into the jar package are:

1. Activity file under the/src/directory

2. Files under the root directory,. Classpath,. Project, Manifest.xml,. Properties,. CFG, etc.

3. Files under the/bin/directory, such as: Manifest.xml,. Dex,. APK, RESOURCES.AP_, etc.

4./bin/res Catalogue

5./res/drawable Related Directories

6./res/layout/Catalogue

7./res/menu/Catalogue

By This step, it has been completed.

The above is how to export the Android project as a jar file, in fact, this is not a problem, because this is the normal generation of jar file situation.

Two other ways to resolve this situation:

(1) to package the activity or resource file :

There are two ways to solve this problem: one http://blog.csdn.net/xiaanming/article/details/9257853

Item 1 is the Library (to send the source code to a third party, unsafe)

(2) Item 1 itself already contains a third-party jar:

Item 1 is the Library (to send the source code to a third party, unsafe), the following "Two" will be detailed.

Is it possible to link a dependent jar file or library by simply packaging the Android project with Eclipse? Does not seem so powerful, after the online query, the entire project packaging is not allowed, the call will be wrong.

2.jar Import

(1) Absolute path method: (absolute path not recommended)

Right-click on "Project" → Select Properties, select Java Build Path from the list on the left of the popup dialog, as shown in: Select Add External JARs, you can select multiple jars individually, But restricted to the same folder) add a third-party reference jar package.

This is easy to do, but each project to invoke Project 1 requires a re-introduction of the jar package, which is not reusable. The jar package absolute address is also prone to error, so it is not recommended.

(2) Custom library method (absolute path not recommended):

Although this method can be reused, it is also an absolute path and is not recommended.

(3) Add a Custom folder method: ( recommended )

Create a new folder (any name) in the project 2 root directory, and then copy the jar file you want to import into this folder, and then:

The check will not error.

Although this method can not be reused, but simple, is a relative path, not easy to make mistakes, recommended to use.

(4) put the jar into the Libs method ( relative path, recommended )

The Add to Build path step is less than Method 3, so it is simpler, is also a relative path, is not easy to error, recommended. (although it is not reusable)

Second, is Library

I have been on the internet for a long time, also read some blog posts, still did not find the right solution.

Some of the use of the SDK, in the Android have to rely on the jar can not be packaged as a jar file, we can use it as a library (libraries) for other projects to refer to, such as the cool SDK using such a library, is an Android project form exists.

How cool it is to set it to the IS Library

How cool the demo is provided is this quote:

For the SDK this piece of my understanding is very shallow, need to have time to do a good study later. If you have a suitable and effective method, please leave a message. If there is an error, please correct me.

Reference:

http://blog.csdn.net/xiaanming/article/details/9257853

http://blog.csdn.net/wwj_748/article/details/21937257

http://blog.csdn.net/mazhaojuan/article/details/21403717

(Android) How to use a high-reusability project for other projects (jar export, import, is Library) (RPM)

Related Article

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.