Glovo Guillermo Mazzola Sep 7, 2021

Publishing Variant-Aware Android Libraries with Source Distribution

Article Summary

Guillermo Mazzola from Glovo cracked a problem that's been frustrating Android library publishers since AGP 7.0: how to ship variant-aware libraries without breaking source code navigation in your IDE.

Android Gradle Plugin 7.0 introduced variant-aware library publishing, letting you ship different debug and release versions of the same library. But there was a catch: IntelliJ and Gradle couldn't resolve source code for variant classifiers, breaking the developer experience. Mazzola's team at Glovo needed both variant awareness AND working source navigation for their internal libraries.

Key Takeaways

Critical Insight

By publishing variants as separate artifacts instead of classifiers, you can have both variant-aware dependencies and working source code navigation in Android Studio.

The article includes a ready-to-use Gradle script that implements this multi-artifact publication strategy for your own libraries.

About This Article

Problem

Glovo's internal Android libraries, like their logger wrapper, needed different behavior depending on whether they were built for debug or release. When they tried to publish these variant-aware libraries, Gradle and IntelliJ ran into a problem: they couldn't find source artifacts when dependencies used classifiers. This resulted in invalid notation like 'library:1.0:debug@aar:sources'.

Solution

Guillermo Mazzola's team switched from AGP's default 'all' component publication to a different approach. They published each variant as a separate artifact and added a variant-aware POM at the original coordinates. This let Gradle select the right variant while keeping Maven's sources classifier convention intact.

Impact

Developers at Glovo can now use IntelliJ's 'Download Sources' feature for variant-aware internal libraries without hitting build errors. They get full source code navigation and the system still picks the right variant based on whether they're building for debug or release.