Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Android custom view library in Android Studio?

I've created a custom view that extends a RelativeLayout for a project I'm working on. I think it might be useful to others, so I've been trying to set it up as a library so others can find and use it.

I've haven't been able to find a clear answer on how to go about setting this up in Android Studio.

To be clear - I have already built the view and it is working fine, I just want to package it up as a library.

Do I create a new project and simply put my code there, or do I need to make a new module too? Once I do either of those things, which parts of the manifest and gradle files do I need to change?

Lastly, do I need to somehow get an AAR from the files or is it best to just upload it to GitHub and let others clone it?

like image 637
student010 Avatar asked Oct 09 '14 18:10

student010


1 Answers

In Android Studio (v 1.0.2):

File -> New module... -> Android Library

In this new module put all the code you want to share. Android Studio should update Gradle's settings accordingly.

You can publish your library as source code and/or artifacts in some Maven/Gradle repository. Publishing source code allow others to contribute to your work, fixing bugs or extending functionality. However, if you just do that, it won't be very convenient to reuse it for other developers, because working with source requires checkout and build. If you publish also artifacts (in some Maven/Gradle repository) built from that code, you will simplify the life of people using your code :)

like image 61
Zbigniew Malinowski Avatar answered Nov 15 '22 01:11

Zbigniew Malinowski