At the beginning of the year, JFrog announced that they were going to close the JCenter repository on which our programming library was hosted, along with many others. We therefore decided to publish our Android programming library on
JFrog announcement surprised everybody. Even more so because the original deadline before the effective closing was very short, as JFrog planned to unplug the servers on May 1st. Since then, the company specified that the repository would be maintained as read-only. That is, all the build scripts could download the old libraries, but developers couldn't publish updates.
As JCenter was very popular, this decision drove many developers to look for an alternative, and this alternative is called mavenCentral.
MavenCentral is a maven library repository which is supported by gradle and Android Studio. It is even automatically used in the new Android Studio projects. It works in the same way as JCenter: you specify the name and the revision of the libraries used in the application. During compilation, the libraries are automatically downloaded and added to the binaries.
Migrating to mavenCentral
We had to adapt many things internally to migrate the Yoctopuce library to mavenCentral, but fortunately things are much simpler for the library users. Indeed, internally, the two repository use maven, so you must simply tell gradle to contact the mavenCentral server instead of the JCenter server.
To do so, you must simply add mavenCentral() in your build.gradle file. Make sure to put mavenCentral() before JCenter so that the build script takes the up-to-date versions on mavenCentral in priority.
allprojects {
repositories {
google()
mavenCentral()
jcenter()
// leave reference to JCenter for old artefacts
// that have not yet been migrate to mavenCentral
}
}
...
If you use Android Studio, you must also force the IDE to synchronize the file again, by using the button on the top right or by restarting the IDE.
The syntax to add a reference to the Yoctopuce library doesn't change (see below). When next compiling, Gradle downloads the Yoctopuce library again from mavenCentral and uses this version.
New projects
The latest version of Android Studio already support mavenCentral. If you look at the build.gradle file generated by the IDE when creating a new project, you can note that the file already contains mavenCentral in the list of repositories.
The content of the build.gradle file generated by Android Studio:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You must then add a reference to "com.yoctopuce.android:YoctoLib" to the list of dependencies for the project to be automatically compiled with the latest available version of the Yoctopuce library for Android.
You can add this dependency directly in the build.gradle file of the application in the "dependencies" section.
android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.yoctopuce.examples.myapplication"
minSdkVersion 15
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.yoctopuce.android:YoctoLib:+'
}
But you can also go through the "Project Structure" window. You must select the application module, open the "dependencies" tab, and add a "com.yoctopuce.android:YoctoLib:+" dependency. By looking for "com.yoctopuce.android", the wizard proposes the latest published version of the library.
Be careful not to confuse the "com.yoctopuce.android:YoctoLib" library with "com.yoctopuce.java:yoctolib". The "com.yoctopuce.java:yoctolib" library is the Yoctopuce library for Java for platforms other than Android. If you use this library, you won't be able to access the modules connected on the USB port.
The dependency window in Android Studio
Conclusion
So our Android programming library is now available on mavenCentral and you can again automatize the installation and use of this library.
Nevertheless, this misadventure revealed the hidden side of all library repositories. Indeed, if the repository server are no longer available, this can break the compilation of a very large number of applications. This type of problem is not only linked to Android. NPM also had troubles in the past, and the same issues could arise on any package repository.
For this reason, all our libraries are also available from GitHub and directly from our web site. In this way, if mavenCentral suddenly decides to close its doors in 5 years time, you can always download the library sources and add them to your project.