Standardization of library versions in Android multi-repo projects

Rodrigo Vianna Calixto de Oliveira
CodandoTV
Published in
3 min readFeb 22, 2022

This article is English version from the Padronização de versões de bibliotecas em projetos Android multi repositórios.

It is often observed that Android projects have a versioning file with all versions of all libraries, in order to control them, therefore, it may be used for different modules in order to ensure that any of them will have the same version.

However, in large projects, conflicts are expected in library version integrations, as outlined in the abovementioned article "Construindo um projeto Android com multi repositórios", which was written by me, or when the entire team wants to keep a determined library version pattern even when working in different projects for the same company. We have detected an
approach to simplify this control and avoid any risks.

This is not the only way to do this, but what we have done was to create a separate repository, with only one versioning file, as shown here:

With this code snippet, which will have the variables declared with their libraries, such as

After that, in the application project, add the "afterEvaluate" block to the root build.gradle, which will be executed when the project is synchronized before the app module build.gradle is executed, resulting in the file being downloaded using the "curl" and added to the project root.Then, it will be added to gradle for all modules through “apply from:”.

Groovy:

Gradle Kotlin DSL:

In the build.gradle of your modules, it is only required to declare the variables being used with the same name as the version.gradle file.

Groovy:

Gradle Kotlin DSL:

Done! Every time you sync the project, the version file with all the libraries you and your team have updated and standardized will be downloaded!

Note: not all places will be public repositories, but this solution also works if you pass the authentication through the URL. URL branch parameters can also be passed in the URL, such as develop, master, and so on.

I would like to state that this solution was conceived and developed with Gustavo Santorio e Estevão Henrique Coelho

That’s all folks!I welcome comments and suggestions. You can make them below or contact me through LinkedIn ou https://flow.page/rviannaoliveira.

--

--