【发布时间】:2018-09-21 06:30:05
【问题描述】:
我们开发了一个 Android 应用程序,我们希望在每次发布后将 apk 部署到我们的 nexus-server。
./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-method。有谁知道问题可能是什么?
这是我的项目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 用于应用程序模块
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 版本(3.0.1 与 2.2.3)。但对我来说,不可能在两个项目中统一 gradle-version。
【问题讨论】:
-
遇到同样的问题?你找到合适的解决方案了吗?
-
正是我在回答中写的。这对我们有用,我们不再花时间解决这个问题。
-
哪里需要添加这行。当我在应用程序 build.gradle 中添加它时,它对我不起作用
-
我们直接将它添加到应用程序 build.gradle 中。使用 gradle 4.1 它可以工作。 android { ... } def releaseFile = file("build/outputs/apk/release/app-release-unsigned.apk-release.apk") 工件 { 档案 releaseFile }