Issue
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 https://developer.android.com/build/publish-library/upload-library, and arrived at the following build.gradle:
plugins {
id 'com.android.library'
id 'maven-publish'
}
android {
namespace 'com.example.mylibbrary'
compileSdk 33
defaultConfig {
minSdk 26
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
publishing {
singleVariant("debug")
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
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?
Solution
Try to run "publish" Task
Add "assembleDebugAndroidTest.finalizedBy publishDebugPublicationToMynewrepoRepository"
Answered By – Rob
Answer Checked By – Mary Flores (FlutterFixes Volunteer)