user1902853
user1902853

Reputation: 419

How to create Android Studio project with ONLY a library module

I'm having a lot of trouble trying to create an Android Studio project with just a library module in it. If I go to File -> New -> New Project, it assumes that I'm making an app, even if I tell it not to create an empty activity. If I then make a library module, I'll have a useless app module in the project as well.

Is there any way to remove that module? I've tried deleting the directory (which seems to confuse Android Studio) and I've tried deleting it through the Module Settings menu in Android Studio (which causes it to be immediately recreated). There must be a way to do this, right?

Upvotes: 2

Views: 1857

Answers (4)

Ben
Ben

Reputation: 329

You don't delete the App module, you convert it to a library per the instructions here: https://developer.android.com/studio/projects/android-library#Convert.

In summary:

  1. Open Android Studio (I'm on Hedgehog | 2023.1.1 Patch 2),
  2. New Project,
  3. Phone and Tablet > "No Activity",
  4. Fill out the new empty project details (I'm calling mine HelloJava),
  5. Finish and wait for sync....
  6. Select Project from the drop-down in the project pane to view the project files,
  7. Expand "app", double click "build.gradle.kts",
  8. Find the "plugins" section and convert "com.android.application" to "com.android.library".
  9. Find the "defaultConfig" section, and remove lines for "applicationId", "versionCode", "versionName"

If you now build, you'll get an AAR instead of an APK.

Upvotes: 1

user1902853
user1902853

Reputation: 419

For anyone who is having this same problem, it appears that you truly cannot delete the app module from an Android Studio project. All projects must have an app module, even if the main purpose is to create a library. I ended up making a small example app showing how to use the library, which appears to be the convention.

Upvotes: 3

Ramoson
Ramoson

Reputation: 1

You can try remove module from project structure;

Upvotes: 0

OneCricketeer
OneCricketeer

Reputation: 192023

You want to make a module, which needs to be part of a project.

Feel free to delete the app module, or actually show example usage of your library, which is what most libraries provide

From Android docs

Create a library module

To create a new library module in your project, proceed as follows:

Click File > New > New Module
In the Create New Module window that appears, click Android Library, then click Next.

Upvotes: 0

Related Questions