I have a library project with a module that is just for library classes and views. I've been searching over the internet how to distribute it in jCenter to use as a gradle dependency but nothing works.
While this isn't done yet, how can I use this module in others projects?
PS: I use Android Studio on Windows 10.
Many of the tutorials and directions online are out of date or are very hard to follow. I just learned how to do this myself, so I am adding what will hopefully be a quick solution for you. It includes the following points
The library you want to share
By now you probably already have a library set up. For the sake of this example I made a new project with one
demo-app
application module and onemy-library
library module in Android Studio.Here is what it looks like using both the Project and Android views:
Set up a Bintray account
Bintray hosts the jCenter repositories. Go to Bintray and set up a free account.
After you sign in click Add New Repository
Name the repository
maven
. (You can call it something else, though, if you want to group several library projects together. If you do you will also need to change thebintrayRepo
name in the gradle file below.)Chose Maven as the repository type.
You can add a description if you want. Then click Create. That's all we need to do in Bintray for now.
Edit the gradle files
I'm going to make this as cut-and-paste as possible, but don't forget to edit the necessary parts. You don't need to do anything with the demo app module's
build.gradle
file, only the gradle files for the project and the library.Project build.gradle
Add the Bintray and Mavin plugins to your project
build.gradle
file. Here is my whole file:The newest version for Bintray is here and Maven is here.
Library build.gradle
Edit everything you need to in the
ext
block below.local.properties
The library
build.gradle
file above referenced some values in thelocal.properties
file. We need to add those now. This file is located in the root of your project. It should be included in.gitignore
. (If it isn't then add it.) The point of putting your username, api key, and encryption password here is so that it won't be publicly visible in version control.There is a warning about not modifying this file but it seems to work well anyway. Here is how you get the values:
bintray.user
: This is your Bintray username.bintray.apikey
: Go to Edit Profile in the Bintray menu and choose API Key. Copy it from here.Upload project to Bintray
Open a terminal and go to your project's root folder. Or just use the terminal in Android Studio.
Enter the following commands
If everything is set up right it should upload your library to Bintray. If it fails then Google the solution. (I had to update my JDK the first time I tried.)
Go to your account in Bintray and you should see the library entered under your repository.
Link to jCenter
In your library in Bintray there is an Add to jCenter button.
Click it and send your request. If you are approved (which takes a day or two), then your library will be a part of jCenter and developers around the world can add your library to their projects simply by adding one line to the app
build.gradle
dependencies block.Congratulations!
Notes
How to add a new version
You will eventually want to add a new version to your Bintray/jCenter library. See this answer to directions on how to do it.
Further Reading