I want to make a separate module so I can share it between projects. The module is going to have android components. So upon creating a new module the options are Phone & Tablet module and Android Library. I wanted to know what's the difference between the two. thanks
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
These modules allow you to store source code and Android resources which can be shared between several other Android projects. To use a Java library (JAR file) inside your Android project, you can simple copy the JAR file into the folder called libs in your application.
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
We recommend using the androidx libraries in all new projects. You should also consider migrating existing projects to ensure they continue to receive bug fixes and other library improvements. The Android Support Library contains several library packages that can be included in your application.
When you build the dependent app modules, library modules are compiled into an AAR file then added to the app module. Therefore, each library has its own R class, named according to the library's package name.
To use your new Android library's code in another app or library module within the same project, add a project-level dependency: Navigate to File > Project Structure > Dependencies. Select the Module in which you’ll use the library. In the Declared Dependencies tab, click and select Module Dependency in the dropdown.
What is Module? From the Add a Module for a New Device documentation:
Modules provide a container for your app's source code, resource files, and app level settings, such as the module-level build file and Android manifest file. Each module can be independently built, tested, and debugged.
What is Android Library? From Create an Android Library documentation:
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest. However, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module. Unlike JAR files, AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods.
You can't access the components from one module to another module. So, if you need to share components between projects, you need to create Android library. But please remember, you can't run the library. You only can access and use it from the module. Furthermore, you can use Gradle Android Maven plugin to install your library locally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With