4 minute read

In an attempt to learn more about Kotlin and to also learn more about publishing and distribution of libraries, I built a library that lets you drag to give rating which also allows you to customise assets to the rating.

For some reason initially I though SlideRating was the perfect name for the library and it was published with that name on Github and bintray as well. (Yes!! I still can’t believe I decided to go ahead with that) Then I felt this name doesn’t do justice to the library and what it provides, so I decided to rename it to DragRating.

Changing the name of library

To change the name of an already published library, I broadly listed down the place where the name will have to be update.

  1. Rename the project (in Android Studio)
  2. Rename the modules, classes and package name in the codebase. (if any)
  3. Change the name of the repo on Github.
  4. Hosting the library with the new name on bintray and jcenter.

1. Rename the name of the project (in Android Studio)

This can be done very easily by following the below steps.

  1. Close your Android Studio project.
  2. Rename the root project directory name from your File Manager (I renamed the project from SlideRating to DragRating
  3. Open Android Studio
  4. Open the new project by browsing to it on Android Studio
  5. Clean build project (This will create all the new files required by the project.)
  6. Add the line rootProject.name = 'DragRating' to the settings.gradle file of the project.

2. Rename the modules, classes and package name in the codebase (if any)

This is a completely optional step and actually depends based on your need. In my case, I had to change the name of the library module, package name and some resource values. Which I did accrodingly.

  1. Rename the module (Refactor -> Rename on module)
  2. Refactor the package (Refactor -> Rename -> Rename Package)
  3. Rename the classes names in the package (Refactor -> Rename)
  4. Rename other files such as values resources and update the comments with the new class names which were not updated (Edit -> Find -> Find in path…) and manually rename those values.

3. Change the name of the repo on Github

This is the easiest of all the steps. We just have to rename the repo and update the new URL of the origin, locally.

  1. Rename the Github repo by opening the project -> Settings -> “Repository name”
  2. Update the remote git repo URL for our local repository. For this run the command git remote set-url origin <<new .git url>> <<old .git url>> in it, replace the <<new .git url>> and <<old .git url>> like this git remote set-url origin git@github.com:saran2020/DragRating.git git@github.com:saran2020/SlideRating.git

4. Hosing the library with the new name on Bintray and jcenter

  1. Create a new repo with the new name on Bintray. Editing an existing repo is not allowed
  2. Create a new package with the name you want for the library to be included in the project with.
  3. Update the Android project to point towards the new repo and make the necessary changes that have to be done, before a new version is sent out.
  4. Upload the new version to bintray, as you would normally do
  5. Send a request to publish the new repo to jcenter. This step can only be done after step 4 because bintray doesn’t allow you to send a request to jcenter for an empty project.
  6. Wait for the repo to be approved by jcenter to be allowed to be published. After it’s approved, you will receive an E-mail. It usually takes a day’s time for the package to be approved.
  7. Congratulations! Your library with the new name has been published successfully.

5. PRO TIPS

  1. Always use Refactor to save all your headache. It will always shows all the changes that will be made for that refactor. It’s a good idea to go through them then, or before committing the changes to git.
  2. It’s a good strategy to keep running the project after every step or after you have made substantial progress.

    Keep committing after every successful run.

  3. Don’t delete the previous repo, because then old users won’t be able to access them. The people who have not updated the dependency will still need the older version.
  4. It’s a good idea to add the change of name to the Readme for the old users coming back to know.

It only took a couple of hours for me, since the project I was migrating was not very big.