![](/img/trans.png)
[英]How to publish artifacts in gradle 4.4 in android studio (Upload APK to nexus)?
[英]Gradle doesn't upload android apk to 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
}
这是我的app-module的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版本。
我们有一个解决方案,但是我们不明白为什么这样做是必要的,并且我们不喜欢硬编码的文件名。
我们只添加了以下几行
def releaseFile = file("build/outputs/apk/release/app-release-unsigned.apk-release.apk")
artifacts {
archives releaseFile
}
这是有效的解决方案吗? 有改进的想法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.