Import the android package into the jar package, package the jar package into the library. KanKanStyle, androidkankankanstyle

Source: Internet
Author: User

Import the android package into the jar package, package the jar package into the library. KanKanStyle, androidkankankanstyle

(1) Import JAR packages to a project: 1. Copy the external jar packages to a libs directory in the project EC or MYec. The old project does not have the lib directory. If it is called lib, an error will be reported. Change it to libs2, right-click the project, and choose Bulid Path> Configure Build Path.
3. In setting the Libraies item, select the location to add the jar package. 3. In the Order and Export items, select the external jar package. (This can be avoided in many cases) 4. After the clean project is re-compiled, the apk package should contain external jar. In MyEc or androidStudio, You can manually refresh it if it is not re-compiled. /(2) importing the library is too simple.
(2) package the project into a JAR package:

It can save a lot of time to publish the package to a forum or github or reference it in another project.
Below, Dana will explain how to package a self-created project into a jar package and how to package an android project into a jar package.

In the dos window, run the command under the bin \ classes file of the project.
Cd file directory

1: If your project needs to introduce data files (slice, txt files, etc.), first put these resource files into the asset files under the project, then copy your asset file to the classes file of your project,
2: Open your local disk, find the workspace folder of your project, find the file name corresponding to your project, and enter the bin folder of the project. We can find the classes file.
3: If your project also references other third-party jar packages, You need to compress the third-party jar package into your project jar package, and copy the extracted file to the classes/com file. I have this com file because the outermost layer of my project package name is com, your own project is determined by your own project and exists in parallel with the file of your project,
4: Run jar-cvf jarname in the dos window. jar *, so that we can see that a jarname is generated in the bin folder. jar file. This file is the package file of our Dana training project.



(3) package the project into a Library project

Studying how to package resources and activity files into jar files for project calls has taken a lot of detours and tried different methods, which is not ideal, finally, we found the perfect solution from the official android documentation. Here is a summary.
This blog post combines the translation of android development documents and the specific situation of individuals in the development process, setting a normal android project as a library project is also a standard android project. Therefore, you must first create a normal android project. This project can start with any name, any package name, and set other fields to be set,
Set the project as a database project. The procedure is as follows:

  • In Package Explorer, right-click the project folder and click Properties.
  • In the Properties window, select "Android" and display the Library property on the lower right side.
  • Select "is Library" and click Apply.
  • Click OK to close the Properties window.
In this case, the project becomes a library project.
Of course, the java project can also be converted into a library project, which is very simple. Execute the above four steps. Other Program projects can reference the library project.

 
Create a manifest file. The manifest file of a library project is the same as that of a standard android Application, declaring all shared components.
For example, in the example of TicTacToeLib in APIDemo, the Library Project declares Activity GameActivity:
<Manifest>... <application>... <activity android: name = "GameActivity"/>... </application> </manifest> Step 2: reference a library project. If your development application wants to include code and resources in the library project, the reference procedure is as follows:
  • In Package Explorer, right-click the project folder and click Properties.
  • In the Properties window, select "Android" and display the Library property on the lower right side.
  • Click Add to open the Project Selection dialog box.
  • Select a project from the list of available library projects and click OK.
  • After the dialog box is closed, click Apply (in the Properties window ).
  • Click OK to close the Properties window.
After completing the above six steps, Eclipse will recreate the project and include the content in the library project.
Sometimes we need to reference multiple databases
If you want to add references to multiple library projects, you can use up and down to set their relative priority and merge order. When the tool merges referenced databases, the order is from low-priority (below the List) to high-priority (above the list ). If more than one database defines the same resource ID, this tool selects a resource with a higher priority. The application itself has the highest priority, and its resources zThe application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries.
Declare the components in the library in the menifest File
In the manifest file, you must add all the components in the library project used in the current program. For example, you must declare any <activity>, <service>, <extends ER>, <provider>, <permission>, <uses-library>, similar to other elements.
When declaring components in a library project, you must use the full name of the class containing the package name.
In the TicTacToeMain example, declare the library Activity GameActivity:
<Manifest>... <application>... <activity android: name = "com. example. android. tictactoe. library. gameActivity "/>... </application> </manifest> requirements
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.