Create library projects and reference for Android Studio

Source: Internet
Author: User

Create library projects and reference for Android Studio

Android Studio creates a library project by creating a Module under the main project. When this Module is created, select the library project mode.
Why? In Android Studio, a WorkSpace is a main Android project. The main project is actually a Module of the workspace, but this Module is a main Module. If you want to create a Library project, it should also be a module project. Set it to Library.
The automatically generated build. gradle file contains a line of labels.
Apply plugin: 'com. android. library'
This line is different from the normal Module project. The normal Module project is
Apply plugin: 'com. android. application'

After a library Module Project is created, a module Module is added to settings. gradle under Project structure.
Include ': app',': mylibrary'

A library Module project has been created.

How can other Module projects reference this newly created library project?
Find the build. gradle file in the Module of the library project to be referenced, and add the following
Dependencies {
Compile project (': mylibrary ')
.......
}
Then, the Reference Library project is successful. You can test to reference the resources of the sub-database project.

Sometimes we need to reference many library projects under a project, and then we want to classify the library projects. We can create folders and put different types of projects under different folders. How can I reference a library project in this case?

In fact, it is very simple. You only need to modify the include ': app',': libs: mylibrary 'in settings. gradle'
Dependencies {
Compile project (': libs: mylibrary ')
.......
}
Here we assume that the new folder is libs.

The record is very simple, but it is amazing for a little white as, haha!

Wait for updates ......

 

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.