Introduction to how Android projects rely on library management

Source: Internet
Author: User
Tags image processing library jcenter

In the actual Android project development process, we will generally use some existing third-party libraries to achieve our needs, avoid repeating the wheel. Commonly used, such as: Network request library, image processing library, interface UI Library (custom view, animation effect, etc.), various third-party SDK libraries (chat, push, etc.). When I first approached Android using Eclipse development, these libraries were managed in the same way: If the jar package is available, the jar package is copied to the Libs directory, and some source libraries are poured into the project as a library, debugged, modified, compiled, and published. One of the serious problems in the early management of this library is that the version cannot be automatically tracked and the update of the library cannot be synchronized automatically. Android Studio is now commonly used in conjunction with Git,maven to develop Android projects. This article through a number of practical scenarios, the AS + git + Maven working method, the process of a simple introduction, I believe that after reading, the reader will be on the Android project package management mechanism has a clear understanding of the overall.

1 found a good library on the GITHUAB, how to use it?

Simply follow the documentation prompts to add dependencies to the Build.gradle. What is going on behind the scenes so that we can use the library only if we need to add a word?

After creating the default project through Android Studio, there is a piece of code in Build.gradle in the project root directory:

allprojects {    repositories {        jcenter ()    }}

This code, equivalent to tell Gradle, if you encounter a dependent library needs to download, to Jcenter to find. What is Jcenter, he is the equivalent of a collection of all public libraries (warehouses). Libraries in Jcenter are managed in a MAVEN package way. The thing behind this is that the author of the GitHub Library has generated a MAVEN package for the code and uploaded the maven package to the Jcenter repository, so gradle can finally download the MAVEN package from Jcenter. This article does not introduce jcenter in detail, just need to know that he is a storage library (storehouse) repository (warehouse) can.

2 project after a period of time, the code will become large and bloated, when the relatively independent, highly reusable modules can be separated into a library, simplifying the project logic code. Let's say we have a module that is independent and made into the library. This library is not only for my own use, other developers have to use, how to do it, it is certainly not a copy of the code. At this point, we can use the Gradle Maven plugin to package the library into a MAVEN package. Other developers can copy only maven packages without copying the source code. Android Studio project, how to use the local maven package? As long as you can tell Gradle encounter dependent library, go to a path to find. The method is configured in the module's Build.gradle:

repositories {    "File:///path/to/maven" }}

Finally, add the compile dependency in the dependencies.

3 It's not scientific to have each developer copy a maven package every time. How to improve? Project code, we generally use git to manage. Similarly, the MAVEN package generated by the library can also be managed with Git. The main project uses Git submodule to manage the Git repository of the MAVEN package generated by the library. In this way, the workflow has been:

Modified by the library:

    1. Modify the library locally, after debugging, commit the code to git
    2. Generate MAVEN packages through the Gradle maven plugin, submit maven packages to another Git repository (the repository that manages MAVEN packages)

Users of the library:

    1. Update the submodule git repository with git submodule update (manage the repository for MAVEN packages)
    2. Modify dependencies dependencies in Build.gradle based on the GroupID, Artifactid, and version information in the MAVEN package
    3. After the Gradle synchronization is complete, you can use the latest library code to develop the main project
    4. After the development, you want to submit the code to the main project's Git repository

4 If the library has no privacy to make public, then we can publish the MAVEN package to Jcenter/maven, just like some libraries on GitHub. In this way, you only need to configure dependencies compile dependencies in the build.gradle of the main project module.

Summarize:

    1. An Android project relies on a library that is essentially a MAVEN package
    2. The MAVEN package can be placed in a public jcenter repository or on a local or some other server
    3. If it is in jcenter, we do not need to configure the warehouse address, the project root directory under the default generated Build.gradle has been configured for us
    4. If it is somewhere else, the local directory, or some other server, you need to use repositories in Build.gradle to configure the specific path of the warehouse, so that when we configure the dependent library in dependencies compile, Gradle only know where to download.

Introduction to how Android projects rely on library management

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.