Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android convert project to library project

Tags:

android

I am trying to convert an Android Studio project as a library.

What is the best way to do this and the steps I need to follow?

What file can I remove from that library project, so that the library look cleaner?

like image 639
Machael.HW.Wong Avatar asked Mar 09 '17 04:03

Machael.HW.Wong


People also ask

What is Android AAR file?

aar bundle is the binary distribution of an Android Library Project. An AAR is similar to a JAR file, but it can contain resources as well as compiled byte-code. A AAR file can be included in the build process of an Android application similar to a JAR file.

What is the difference between AAR and jar?

The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.


1 Answers

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.

Convert an app module to a library module

Open the build.gradle file for the existing app module. At the top, you should see the following:

apply plugin: 'com.android.application'

Change the plugin assignment as shown here:

apply plugin: 'com.android.library'

Also in this file, you have to delete this line

applicationId "your.application.id"

Click Sync Project with Gradle Files.

Check this for more details https://developer.android.com/studio/projects/android-library.html

like image 74
Gopal Avatar answered Oct 14 '22 01:10

Gopal