Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phone and tablet Module vs Android Library

Tags:

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

like image 644
Zeyad Gasser Avatar asked Aug 29 '17 22:08

Zeyad Gasser


People also ask

What is Android library module?

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.

What is Java module in Android Studio?

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.

What is the difference between an Android library and module?

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.

When should I use the androidx libraries?

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.

What is the difference between dependent app module and library module?

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.

How do I use an Android library in another project?

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.


1 Answers

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.

like image 58
ישו אוהב אותך Avatar answered Oct 07 '22 18:10

ישו אוהב אותך