19

I need to create an Android Library and deliver the final .jar file to the clients.

I am new to Android development (three days). I've been developing iOS for the last 4 years. I went through Google's official documentation and tutorials to get a feel for the platform (I don't want it to be obvious that an iOS guy was writing the library).

I don't have any problems with Java, but I do with Android. I decided to go with Android Studio since it is the official IDE. I am using version 1.5.

PROBLEM:

So as I said, I need to create an Android Library and deliver the .jar file to the clients. I would like this Android Studio project to be a standalone library project with its own unit tests. I don't want to create an unnecessary App project, and then add an Android Library module to it. I want to create a separate App project which will include this .jar file, so I can test it in the way it will reach our clients.

I've seen a lot of options online for how to accomplish this, but all of them seem a bit "hacky" (e.g. rename this folder, change that app-project-setting and make it a library project). Is there no way to create a Library project from a new project wizard in Android Studio?

What are your suggestions on how I should proceed with this? Is there some elegant solution to this without these tricks to re-configure the App project?

EDIT

Here is what the new project wizard looks like: enter image description here

enter image description here

I select "Add no activity" here enter image description here

Jantzilla
  • 638
  • 1
  • 7
  • 19
vale4674
  • 4,161
  • 13
  • 47
  • 72
  • I seem to remember reading that if you uncheck all of the options on the Target Android Devices screen, it won't create the `app` module. Then you don't have to delete anything before creating the module type that you actually wanted. (Not posting this as an answer because I don't use Android Studio, precisely because of stupid things like this.) – Kevin Krumwiede Nov 28 '15 at 03:58
  • 1
    @Kevin Krumwiede - it doesn't appear so. a message appears in red at the bottom of the dialogue letting you know that "At least one form factor must be selected". – homerman Aug 22 '16 at 01:46

2 Answers2

29

This may not feel comfortable for a person from other platform/IDE/world, but this is The Way. Personally i'm getting annoyed with Xcode every time i use it in the exact same way you're annoyed with AndroidStudio now. But lets get down to business:

  1. Create an empty project and select "Create no activity". enter image description here
  2. When everything is set, go to "File\New\New Module" and select "Android Library" enter image description here
  3. Give a name for created library and click "Finish".
  4. (Optional) go to "Run\Edit Configurations" and set everything like below: enter image description here

  5. Now open the librarie's 'build.gradle' file. Make sure to open the file from exact same folder which is named with your library name, because there are a couple of 'build.gradle' files all over the place. Remove support-library entry from the file: enter image description here

  6. Write some code and when you're ready to deploy the library set everything like this: enter image description here

Go to "Build" menu at the top and select "Build APK".

And about unit tests: enter image description here

**Edit 1: **

If you really want to remove the 'app' folder, than follow instructions on a picture below: enter image description here

mykolaj
  • 974
  • 8
  • 17
  • 2
    So there is no way to avoid creating of "app" folder? – vale4674 Nov 30 '15 at 12:03
  • So I got the AAR file now. How can I use it in my current project? Import it with Graddle ? – Karl-John Chow Dec 15 '15 at 03:35
  • Thank you. There is no option in Android Studio 1.5.1 to "Remove module" when right clicking it from within the Library project.. I don't specifically need it gone, but it would be clean if it were. – Mullazman Feb 10 '16 at 04:36
  • very nice tutorial! To be honest, I've used several IDE's in my time and when starting a new project, there has always been an option such as "Library Project [ ]". a checkbox like this would definitely be user-friendly to have on the "New Project" screen in Android Studio – Someone Somewhere Mar 24 '16 at 11:43
  • 1
    @Mullazman After you have the 'app' entry removed from the 'settings.gradle' file, and AS rebuilds a project, the 'app' folder is not considered as a part of the project anymore. You could notice this because the 'app' label font becomes not bold. After that you can remove this folder in any way you prefer: either directly from the file system by using a file manager, or by right clicking in AS project view and choosing 'Delete'. – mykolaj Mar 24 '16 at 12:37
0

You can create Library Project instead of Normal Project,then your output product will be a jar or aar as you configured.If your library has resources then build it as aar,or it will be jar.

When you created a project as yo are doing,click File->new Module,then will like this:

If your library project have resources or will use API of Android,then choose Android Library,else choose Java Library,Android Library will build aar as product whild Java Library build jar product.

starkshang
  • 8,228
  • 6
  • 41
  • 52