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
- AGP 7.0's 'all' component publishes variants as classifiers but breaks source resolution
- IntelliJ builds invalid notation like 'library:1.0:debug@aar:sources' when downloading sources
- Solution: publish each variant as separate artifact plus variant-aware POM at original coordinates
- Gradle engineers acknowledged the issue but no official fix yet available
By publishing variants as separate artifacts instead of classifiers, you can have both variant-aware dependencies and working source code navigation in Android Studio.
About This Article
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'.
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.
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.