How Android Studio adds dependencies

1. Sometimes you need to add a dependency when writing a project. For example, I need to use Bluetooth, but I don’t want to write it myself. I can find a mature and stable Bluetooth project from the Internet, add a folder to my project and give it a name, and then copy the found Copy the content under the app path in the project
insert image description here
to the new folder of your own project, so that it becomes an internal module, and then change the module declaration
insert image description here
application in the module build.gradle to library, and the dependency is added , you can call the Bluetooth function in this module in your own project.
After adding, the icon will change from the folder to this with a bar graph in the lower right corner, which means the addition is successful.

insert image description here
2. There are also internal libraries that add jar and aar, put them in the /Project/module/libs/ directory, and then add them under the dependencies tag in the module configuration /Project/module/build.gradle:

compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'FileSelector-release', ext: 'aar')

Android studio will automatically load the dependent libraries in the specified directory.
3. Everyone knows the method of adding external libraries, after all, this is the most used one. Declare the warehouse in the /Project/build.gradle file. In the automatically generated project, AS will be configured by default. The default central warehouse is jcenter, and maven can also be used.
For example, the most commonly used greendao, add it under the dependencies tag in the build.gradle file

//greenDAO配置
    implementation 'org.greenrobot:greendao:3.3.0'
    implementation 'org.greenrobot:greendao-gradle-plugin:3.3.0'

Then click sync now to add it.

Guess you like

Origin blog.csdn.net/qq_35761934/article/details/128638965