You can also add a library in Android Studio by adding it as a module. To add the module:
- First, place the library code in any folder of your choice
- Then, you need to Import the library as a module in your app. The figure below shows the steps to add the library as a Module:
This will open a new window where you need to select the library that you have saved to the directory. When you have selected the directory, click on Done. This will import the external library into your project.
As an example, I have added the module crop image to my project, which appears in my project folder.
Next, we need to add the module to the app's dependency list. To do this, right click on the module that has been added and click on the Open Module Settings option:
It will open a new window with your app module and library module in the list. Choose you app module, and then select the dependency list.
Next, click on the plus icon which will open another dialog with the module name. Select it and click OK:
This will build the Gradle and add the module to the build.gradle, and it will be seen as a compiled project here:
Note that Core, UI and Util sub projects can also have their own build.gradle file, depending on their specific needs. Alternatively, you can also define the dependencies of a project in the root build.gradle file, as discussed in the preceding section. In this case, we won't be focusing on these points.