How to get gradle to publish to a local meven repo


I’ve created a simple sample library using Android Studio.

My goal is that when building the module, it publishes it to a maven repo on the local file system to be consumed by another process.

I’ve followed the instructions from, and arrived at the following build.gradle:

plugins {
    id ''
    id 'maven-publish'

android {
    namespace 'com.example.mylibbrary'
    compileSdk 33

    defaultConfig {
        minSdk 26

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles ""

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), ''
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

    publishing {

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation ''
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

publishing {
    publications {
        debug(MavenPublication) {
            groupId = 'com.example'
            artifactId = 'mylibbrary'
            version = "1.0"

            afterEvaluate {
                from components.debug
    repositories {
        maven {
            name = 'mynewrepo'
            url = "file://${project.buildDir}/repo"

However, it seems that the publish task for this gradle file never actually runs when building the module, despite mylibbrary-debug.aar ending up in MyLibrary\mylibbrary\build\outputs\aar.

How can I get this to publish to the repo in MyLibrary\mylibbrary\build\repo\mynewrepo?


Try to run "publish" Task

Add "assembleDebugAndroidTest.finalizedBy publishDebugPublicationToMynewrepoRepository"

Answered By – Rob

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *