What happened: after being in read-only mode for over 3 years, jCenter has officially shut down on August 15, 2024. (https://jfrog.com/blog/jcenter-sunset/)
In a perfect world, 3 years is more than enough time to migrate but the reality, of course, is different and there were still projects relying on jCenter, for whatever reason. I recently had to revive an old project that hasn’t been updated in a while and this article is based on that experience.
How to know if you’re affected:
1. Check if you have jCenter() anywhere in your gradle files. If you don’t, you’re good.
2. Does your app still build? That’s a good sign but if you’re building locally, you’ve probably had all of your dependencies cached for a long time.
Try renaming the ~/.gradle folder to something else in order to simulate a clean build, as if you were building on a new machine.
Open Android Studio and try to build the app (actually build, not just gradle sync).
If your app still builds, congratulations, this means jCenter was referenced in your gradle files but none of your dependencies were actually pulled from there, so you’re good.
However, if you are unlucky enough to see errors like
"Could not resolve all files for configuration […]
> Could not resolve [...]",
that means some of your dependencies were indeed hosted on jCenter and aren’t available anymore.
The errors are likely caused by some random obscure libraries that haven’t been maintained in years, if not a decade.
What you can try:
1. Search the library on https://mvnrepository.com
See if it has been published somewhere else, like maven central. If it has, then it’s an easy fix, just upgrade to the version that’s available. Note though that if you are upgrading from a very old version, there might have been breaking changes, which can complicate things.
2. Find the library on Github.
Check the issues, maybe someone posted a solution there. Or if the library was popular enough, someone might have taken over the maintenance and a newer version is available under a different name.
3. Find the library on Jitpack (https://jitpack.io)
Jitpack can basically build the library from source code (like Github) and host the artifact for you, which you can depend on.
Find the library you need and see if there are any versions available (there should be a green “Get it” button).
You can also request a build (or a specific version) by clicking Get it.
If this option works, that’s also an easy fix. Just add the Jitpack build.
But it’s not guaranteed to work because if you are dealing with very old unmaintained libraries, they might not even build anymore.
4. Remove the dependency, if possible
Do you really need this library? If you’ve made it this far, that’s a very valid question to ask.
You can still find a way to resolve the dependency but the library itself will remain unmaintained, just adding to the overall tech debt.
If you are working with an unfamiliar legacy codebase, check how that library is actually used, it may be easy to remove / migrate to something else. Or it might not be used at all, if someone just added a bunch of libraries when the project was created.
5. Check your gradle cache for the jar/aar file
Remember the cached dependencies thing from the beginning of the article.
If the app still builds for you or for someone on your team, you can extract the jar/aar file from the .gradle folder and add it to your project.
The cache should be located in ~/.gradle/caches/modules-2/files-2.1/
6. Find the jar/aar somewhere else
If no one actually has the file, try searching for it on google, maybe you’ll find somewhere to download it from.
I was able to download some aars from what seemed like some company’s Artifactory.
7. Try to build the library yourself or add the source code to your project
If all else fails, you probably need to just check out the source code, resolve the errors and build it yourself. The most time-consuming option.
This list is roughly ranked from best to worst options. There isn’t really a one-size-fits-all here, each case is different and this process can be easy or difficult, depending on your luck.