Library project
Compile project (': library ')
The reference name is the module of the library. It should be noted that the referenced module needs to be registered in the {@projectName}/settings.gradle file.
We can observe that the Apply plugin used in Library/build.gradle is ' com.android.library '. Used to mark this as an Android Library Project.
Of course, you can also rely on a Java Project, apply plugin as ' Java '.
The creation of the library project in Android Studio is actually created by creating module modules under the main project, which selects the Library project mode when the module is created.
Why do we have to deal with it? Because a workspace workspace in Android Studio is an Android master project. The main project is actually a module in this workspace, except that this module is a master module.
If you want to create a library project, it is obvious that it should be a module project, set up as a library.
Then the auto-generated Build.gradle file will be marked with a line.
Apply plugin: ' Com.android.library '
This line is distinguished from the normal module project, and the normal module project is
Apply plugin: ' Com.android.application '
After a library module project has been created successfully, there will be a module in the Settings.gradle in project structure
Include ': App ', ': MyLibrary '
Such a library module project is already created.
How do I get other module projects to refer to this newly created library project?
Locate the Build.gradle file in the module that needs to reference the library item, and add the following
dependencies {
Compile project (': MyLibrary ')
.......
}
Then again, the Reference Library project was successful. You can test the resources under the Library project under reference.
Sometimes we need to refer to a number of library projects under a project, and then the library project wants to categorize, you can create folders, and then put different types of items into different folders. How do you cite library projects in this situation?
Actually very simple, just need to modify the include ': App ' in Settings.gradle, ': Libs:mylibrary '
dependencies {
Compile project (': Libs:mylibrary ')
.......
}
This assumes that the newly created folder is Libs.
Specific operation look at the picture:
Similarly, open project structure, click on the module you want to use as the library, then click Android, and in the right frame, before the library module √.
Select the module you want to refer to, such as the Red box button.
In the popup dialog box, select the library module you want to refer to (there will be several module on this side depending on how many module you have set to Lirary module)
Click OK, you can see the Export box appears in the library module you introduced, select the Library module, and then Apply,ok.
Android Studio Learn----Add a project library