Quick and Dirty Guide to Publishing an Android Library with Maven-Publish

Carter Hudson
1 min readJun 26, 2022

These days, you have to use the maven-publish plugin to publish your Android library to a repository, even if you just want to use jitpack. It’s a huge pain in the ass for a couple reasons:

  • The documentation is protracted and ambiguous.
  • ./gradlew publishToMavenLocal doesn’t publish to ~/<USER_HOME>/.m2/repositories by default

For my own edification in the future, here’s a barebones example of exactly what worked for me:

android {
...

publishing {
singleVariant('release')
}
...
}
publishing {
publications {
release(MavenPublication) {
groupId 'com.example'
artifactId 'artifactId'
version = android.defaultConfig.versionName

afterEvaluate {
from components.release
}
}
}
}

Jitpack was also angry about the Android Library Plugin version I was using, so watch out for that as well.

Maven local builds will appear in your library’s build folder unless you change the directory in the publications block. The following should work:

publishing {
publications {
...
}
repositories {
mavenLocal()
}
}

--

--