Use Android Studio to create AAR files and reference them in other projects
AAR (Android Archive) is the Android archive file, which can package all .class files, manifest files, resource files, etc., for reference by other projects.
Below, take the creation of a custom control and make it into an AAR package (.aar suffix) for other projects to call (use Android Studio version 4.1.1) as an example:
1. Create an Android project, the project name is CustomControl.
2. Create a new module (File -> New -> New Module), select the module type as Android Library and the module name as customlibrary.
3. Create a directory named res and its related directories (such as drawable, layout, values, etc.) to store the corresponding resource files.
4. Create a custom control CustomView layout and Java files (including a TextView and an EditView).
5. Compile into an AAR package (click to run the assemble of the corresponding module under Gradle, and you can see that the release version and debug version of the AAR package are generated in the directory of the corresponding module).
6. Create a new project named TestAar, and copy the AAR package generated before to the libs directory of the project.
7. Import the AAR package (File -> New -> New Module -> Import .JAR/.AAR Package).
8. Quote the AAR package in the project (File -> Project Structure).
9. After quoting, you can see that dependencies are automatically added in build.gradle.
10. Then you can call the custom control CustomView in the AAR package in the project.