Tobias Hein
Tobias Hein

Reputation: 81

Gradle doesn't upload android apk to nexus

we develop an Android App and we want to deploy the apk to our nexus-server after every release.

With ./gradlew -i clean build uploadArchives I get the following output on the gradle-console

:app:uploadArchives (Thread[Daemon worker,5,main]) started.
:app:uploadArchives
Putting task artifact state for task ':app:uploadArchives' into context took 0.0 secs.
Executing task ':app:uploadArchives' (up-to-date check took 0.0 secs) due to:
    Task has not declared any outputs.
Publishing configuration: configuration ':app:archives'
Publishing to org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer@5b0bf3bd
:app:uploadArchives (Thread[Daemon worker,5,main]) completed. Took 1.753 secs.

What does this mean? Did the upload fail? Or wasn't there an apk to be uploaded?

I created a simple HelloWorld Project in AndroidStudio. The only thing I changed was the uploadArchives-method. Does anyone have an idea, what the problem could be?

Here is my build.gradle for the project

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And here my build.gradle for the app-module

apply plugin: 'com.android.application'
apply plugin: 'maven'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.helloworld"
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

uploadArchives {
    repositories.mavenDeployer {
        repository(url: nexusDeployUrl + 'releases/') {
            authentication(userName: nexusDeployUser, password: nexusDeployPassword)
        }
        snapshotRepository(url: nexusDeployUrl + 'snapshots/') {
            authentication(userName: nexusDeployUser, password: nexusDeployPassword)
        }
        pom.groupId = 'com.example'
        pom.artifactId = 'helloworld'
        pom.version = "${android.defaultConfig.versionName}"
    }
}

And my gradle-wrapper.properties

#Wed Apr 11 12:44:57 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Additional information: We have another older android app from where I copied the uploadArtifacts-method. In that app, the upload to nexus works without problems. The only difference I can see (instead of a much huger build.gradle) is the gradle-version (3.0.1 vs. 2.2.3). But for me it was not possible to unify the gradle-version in both projects.

Upvotes: 4

Views: 1252

Answers (1)

Tobias Hein
Tobias Hein

Reputation: 81

We have a solution, but we don't understand why this is necessary and we don't like the hard coded file-name.

We just added the following lines

def releaseFile = file("build/outputs/apk/release/app-release-unsigned.apk-release.apk")

artifacts {
    archives releaseFile
}

Is this a valid solution? Are there any ideas for improvements?

Upvotes: 2

Related Questions