How to publish an Android .aar file to Artifactory

Bungles

I have an Android .aar project called "myLibAndroid". The directory structure has a root-level "build.gradle" file and a sub-directory called "library" that also contains a "build.gradle" file. The .aar file builds fine but fails to publish to Artifactory.

Here is my top-level "build.gradle" file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://artifactory.mycompany.local/artifactory/libs-releases-local'
        }
    }
}

Here is the "build.gradle" file from the "library" directory:

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

def packageName = 'com.mycompany.myLib.myLibAndroid'
def libraryVersion = '0.0.1'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName libraryVersion

        setProperty("archivesBaseName", "myLibAndroid-$libraryVersion")
}

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

publishing {
    publications {
        aar(MavenPublication) {
            groupId packageName
            version = libraryVersion
//            artifactId project.getName()
            artifactId "$archivesBaseName"

//              artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
            artifact("$buildDir/outputs/aar/$archivesBaseName-release.aar")
        }
    }
}

artifactory {
    contextUrl = 'http://artifactory.mycompany.local/artifactory'

    publish {
        repository {
            repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'
            username = artifactory_username
            password = artifactory_password
        }

        defaults {
            publishArtifacts = true
            publications('aar')

            // Properties to be attached to the published artifacts.
            properties = ['qa.level': 'basic', 'dev.team': 'core']

            // Publishes everything by default so just turn off what's not desired
            publishIvy = false

            // Is this even necessary since it's TRUE by default?
            // Publish generated POM files to Artifactory (true by default)
            publishPom = true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
}

tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }

task copyNativeLibs(type: Copy) {
    from '../../libs/android'
    include '**/*.so'
    into 'src/main/jniLibs'
}

clean.dependsOn 'cleanCopyNativeLibs'

Here are the results of "gradlew artifactoryPublish":

[buildinfo] Not using buildInfo properties file for this build.
:library:generatePomFileForAarPublication
:library:artifactoryPublish
Deploying artifact: http://artifactory.mycompany.local/artifactory/libs-release-local/com/mycompay/myLib/myLibAndroid/myLibAndroid-0.0.1/0.0.1/myLibAndroid-0.0.1-0.0.1.aar
:library:artifactoryPublish FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':library:artifactoryPublish'.
> java.net.SocketException: Connection reset by peer: socket write error

BUILD FAILED

Total time: 5.71 secs

Note: The deploy/publish URL that I WANT so that it matches how our Artifactory currently publishes things would be:

    http://artifactory.mycompany.local/artifactory/libs-release-local/com/mycompay/myLib/myLibAndroid/0.0.1/myLibAndroid-0.0.1.aar

The first issue is fixing the artifact URL, which has multiple errors related to the version number. The second issue is what's causing the Java SocketException.

It seems like these Gradle files are close to working properly, so hopefully a small change or two should fix things?

kevinmm

Most likely, the Socket error is due to incorrect Artifactory login credentials and/or permissions. Have you tried checking the Artifactory access logs? I saw the same for someone entering the wrong username.

<artifactory_url>/webapp/#/admin/advanced/system_logs -> access.log

2016-05-10 13:12:52,252 [DENIED LOGIN]  for [email protected]/xxx.xx.xx.xx.
...

I don't see anywhere where you are setting artifactory_username and artifactory_password in your build script.

username = artifactory_username
password = artifactory_password

These need to actually be string values. From the Gradle Artifactory Plugin doc

username = 'resolver'       //Optional resolver user name (leave out to use anonymous resolution)
password = 'resolverPaS*'   //The resolver password

I like to use something like a property here, probably what you intended to do. Something like this:

username = project.hasProperty('repositoryUser') ? repositoryUser : ''
password = project.hasProperty('repositoryPassword') ? repositoryPassword : ''

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to sign AAR Artifacts in Android?

How to configure Maven2 to publish to Artifactory?

How to script Gradle in order to publish shadowjar into Artifactory

Publish binary file to maven artifactory along with JAR files using Jenkins

Create aar file in Android Studio

Publish an Android library to Maven with aar and source jar

How to publish aar file to Apache Archiva with Gradle

Publish an aar file to Maven Central with Gradle not working

How to exclude a file from an .AAR Android library archive with gradle

How to import a .aar file into Android Studio 1.1.0 and use it in my code

Publish .aar file with javadocs attached on artifactory repo

How to remove .aar file form Android Studio

Android Studio Create AAR using another AAR file and jar inside

How to build Flutter project with Android aar file?

Export Android Library as AAR file

How to convert an .aar file into a .jar

How to get packagename of aar file?

How to build CHAQUOPY Android library (.AAR or .JAR file) in Android Studio

How to publish/deploy a npm package to custom artifactory

How to publish custom artifacts to Artifactory from TeamCity?

Easiest way to publish AAR

publish my android aar to jcenter

How to use the downloaded maven aar file in my Android project?

How to publish in my maven local repository an existing aar with gradle?

how to deploy a URL file into artifactory

How do I publish Gradle plugins to Artifactory?

How can I add docstrings to android maven-publish .aar files in build.gradle.kts?

How to download leakcanary-android aar file

How to choose only .aar file from file manager in android