In Android Studio, how can I change the application project to the library?

I am sure it is simple, but since I just started using Android Studio today, I can not find it. I also searched googled in the last hour and did not find any messages that indicate:

how to change an existing application project to a library.

All I have found is how to create a new library project. Not how to convert.

Subquery, how can I see if the project is configured as an application or library? I hope that the answer to both of these questions will be the same.

+5
source share
1 answer

Open build.gradle your application (inside your application directory) and change:

 apply plugin: 'com.android.application' 

with

 apply plugin: 'com.android.library' 

If you have applicationId in build.gradle , delete it:

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

then clean up the project and rebuild or just sync your gradle with Android Studio

If you added some additional gradle properties, such as applicationVariants.all , you should replace it with libraryVariants.all and vice versa if you convert the library into an application

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

+6
source

All Articles