Implementation method of Android custom component into jar package

The implementation method of Android custom components into jar packages. Here, the jar packages of the Android view components implemented by yourself are processed.

In the process of project development, we will inevitably use ourselves to make custom view controls, and then we will directly copy them to the corresponding project if necessary in other projects. Although this is a way to solve the problem, it is not very good after all.

The reason is that when we accumulate more and more projects, we will find more and more custom controls, and these custom controls can be reused. At this time, we can think about how to package these custom controls into a jar package and accumulate them with a project, After that, as long as our future development projects are extended or directly used on the basis of the original jar package, we can greatly reduce our work repeatability.

First of all, the basic appearance of Android project is as follows:

Of course, I deleted the corresponding activity file, because we don't need the activity file when compiling into a jar package.

Taking the above project as an example, we package it into a jar package. The steps are as follows:

Right click the project and select export:

Select export target: Java - > jar file:

Check out some unnecessary documents, as shown in the following figure:

At this step, it has been basically completed. Browse and select the jar file export path.

After the export, we can use our own custom control package like other jar files. Here is a small demo that describes how to use this jar package.

Step 1:

Create a new folder lib and put the jar package in.

Step 2:

Associate jar packages, as shown in the following figure:

Step 3: use the jar package:

The following code:

One bad thing is that if there are use attributes in your project, you must also copy the attributes to the project you want to use, otherwise you will not be able to recognize them.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>