Convert Existing Project to Library Project in Android Studio

Android convert project to library project

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

How to convert an android project into a library project in Eclipse?

Update for Android Studio option

Convert an app module to a library module

If you have an existing app module with all the code you want to reuse, you can turn it into a library module as follows:

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

    apply plugin: 'com.android.application'

  2. Change the plugin assignment as shown here:

    apply plugin: 'com.android.library'

  3. Click Sync Project with Gradle Files.

That's it. The entire structure of the module remains the same, but it now operates as an Android library and the build will now create an AAR file instead of an APK

Read more about how to Create an Android Library and how to Convert existing project to library project in Android Studio


Below steps are for Eclipse

Steps are

Right click on project -> property -> Android -> check 'Is library' check box -> OK

That's it.

Can I convert an already existing project into library project in android?

Assuming you have imported both the projects in the same workspace,

Right Click on your new project -> Properties -> Android -> Library -> Select the existing project as a library for the new project

Also, for the existing project :

Right click on your existing project -> Properties -> Android -> Check 'Is library' check box to enable the project to be used as a library

in Android Studio, how can I change an app project to a library?

Open your build.gradle of your app (inside your app directory) and modify :

apply plugin: 'com.android.application'

with

apply plugin: 'com.android.library'

If you have an applicationId in your build.gradle remove it :

defaultConfig {
applicationId "com.your.application.id"
}

then clean your project and rebuild or just sync your gradle from Android Studio

If you have added some extra gradle properties like applicationVariants.all you must replace with libraryVariants.all and vice-versa if you convert a library to application

If you want to add a new step to your reconversion you can change the module name "app" created by default by Android-Studio with a name more adapted to a library module. You can rename the directory app with <your_module_name>. open settings.gradle file (at the root of your project) and replace app with <your_module_name>. Then Go to Menu Build > Make module <your_module_name> and there you are, your module is renamed.

How to create *.aar file from existing android studio project ( Not creating new android library)?

I did what morrison said I got that error which i sent as photo
the solution for that error was just to "Rebuilt project" after "File/Sync project ..."
( which is funny :) )

now I have aar file in my app/build/...

result as *.aar



Related Topics



Leave a reply



Submit