I'm sure this is simple, but since I just started using Android Studio today, I can't find it. I have also googled for the past hour and found no posts that specify:
how to change an existing application project to a library.
Everything I found was about how to create a new library project. Not how to convert one.
A sub-question, is how can I see if a project is configured as an application or a library? I would hope that the answer to both of these questions is the same.
Using library projects helps you to structure your application code. To create a new library module in Android Studio, select File New Module and select Android 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With