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:
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'
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/...
Related Topics
Rendering Problems in Android Studio V 1.1/1.2
Android Button Background Color
How Do Cursorloader Automatically Updates the View Even If the App Is Inactive
How to Change Background Image of Button When Clicked/Focused
Camera in Android, How to Get Best Size, Preview Size, Picture Size, View Size, Image Distorted
Firebase Authentication State Change Does Not Fire When User Is Disabled or Deleted
How to Send Location of the Device on Server When Needed
Viewpager Offscreen Page Limit
How to Draw Dashed Polyline with Android Google Map Sdk V2
How to Send JSON Object to the Server from My Android App
Change Date String Format in Android
Copy Database File to Sdcard in Android
Install App via Usb: the Device Is Temporarily Restricted
How to Enable and Disable a Component
Android Maps API V2 Draw Circle
How to Use Default Android Drawables
How to Download a Video File to Sd Card
Change Shape Solid Color at Runtime Inside Drawable Xml Used as Background