Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish an Android .aar file to Artifactory

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?

like image 665
Bungles Avatar asked Oct 30 '22 07:10

Bungles


1 Answers

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 : ''
like image 113
kevinmm Avatar answered Nov 09 '22 10:11

kevinmm