Josh Kasten
Posted on April 20, 2021
Google's Android Studio defaults to the JCenter repository for non-Google artifacts. Unfortunately, JFrog, the maintainers of JCenter, recently announced that they are soon sunsetting JCenter.
Breaking down JFrog's announcement, this means the following for Android developers for their app's dependencies:
- March 31st 2021 - Libraries in JCenter will no longer be updated.
- February 1, 2022 - JCenter will be completely shut down.
All Android developers should switch off of JCenter in order to continue getting updates to libraries and SDKs that they use. OneSignal and many other libraries are already available on Maven Central, so migrating is a safe and simple process.
Follow the steps below to make the switch:
Step 1: Add Maven Central to your project to ensure OneSignal continues to get updated.
- Open your root
build.gradle
- Find lines that say
jcenter()
and addmavenCentral()
before each of them (Make sure to addmavenCenteral()
in both spots wherejcenter()
is found.)
After this change, your build.gradle
should look like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral() // New line
jcenter()
// NOTE: Keep any other entries you may have had here
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
//... no changes here
}
}
allprojects {
repositories {
google()
mavenCentral() // New line
jcenter()
// NOTE: Keep any other entries you may have had here
}
}
āļø Sync Gradle by pressing "Sync Now" in Android Studio.
Step 2: Fully migrate off of JCenter.
This section is optional until February 1, 2022 but we recommend following it today since JCenter has been less reliable as it sunsets. The following steps will also allow you to discover any other dependencies you have on JCenter.
You may have noticed that adding Maven Central before JCenter means Maven Central will be used by default, and JCenter will still be used as a fallback.
If you attempt to remove jcenter()
completely today from your Android project, you may get the following error.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find org.jetbrains.trove4j:trove4j:20160824.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
Required by:
project : > com.android.tools.build:gradle:4.1.2 > com.android.tools.build:builder:4.1.2 > com.android.tools:sdk-common:27.1.2
The reason for this error is that the Android Core dependency still requires JCenter.
Android Studio 4.1.2 and AGP (Android Gradle Plugin) still require a version of a dependency (trove4j) that is only on JCenter.
- This is solved in AGP 4.2.0, but this is still in beta and requires Android Studio 4.2 beta or newer.
To fix the missing trove4j
error, you can force an upgrade to a newer version that is available on Maven Central by adding the following to the bottom of your root build.gradle
.
// Temporary workaround for missing trove4j when removing jcenter() until you can upgrade to "com.android.tools.build:gradle:4.2.0"
buildscript {
configurations.all {
resolutionStrategy {
eachDependency {
// https://issuetracker.google.com/issues/109894262#comment9
if (requested.group == "org.jetbrains.trove4j" && requested.name == "trove4j" && requested.version == "20160824") {
useTarget("org.jetbrains.intellij.deps:trove4j:1.0.20181211")
}
}
}
}
}
If you encounter other "could not resolve" errors:
You may find that not all libraries or SDKs in your project are on Maven Central.
If you still see build errors after removing jcenter()
, please check your build log and contact the vendors of those dependencies on to get guidance on their migration strategy. Keep in mind that JCenter will no longer work after Feb 1, 2022.
OneSignal Resources & Support
To continue getting OneSignal Android SDK updates after March 31, 2021, make sure to add Maven Central to your project by following the above guide. OneSignal is already hosted on Maven Central, including the latest OneSignal SDK and all previous versions.
If you have any OneSignal issues with the upgrade you can contact OneSignal supportvia the dashboard, or post your question on this GitHub issue.
Posted on April 20, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.