Gradle没有将android apk上传到nexus

时间:2018-04-11 11:28:16

标签: android gradle nexus

我们开发了Android应用程序,我们希望在每次发布后将apk部署到我们的nexus服务器。

使用./gradlew -i clean build uploadArchives,我在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.

这是什么意思?上传失败了吗?或者还没有上传的apk?

我在AndroidStudio中创建了一个简单的HelloWorld项目。我唯一改变的是uploadArchives方法。有没有人有想法,问题可能是什么?

这是项目的build.gradle

// 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
}

这是我的build.gradle 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}"
    }
}

我的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

其他信息:我们有另一个较旧的Android应用程序,我从中复制了uploadArtifacts方法。在该应用程序中,上传到nexus可以正常工作。我能看到的唯一区别(而不是更大的build.gradle)是gradle-version(3.0.1 vs. 2.2.3)。但对我来说,不可能在两个项目中统一gradle-version。

1 个答案:

答案 0 :(得分:0)

我们有一个解决方案,但我们不明白为什么这是必要的,我们不喜欢硬编码的文件名。

我们刚刚添加了以下几行

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

artifacts {
    archives releaseFile
}

这是一个有效的解决方案吗?有没有改进的想法?