[英]How to publish artifacts in gradle 4.4 in android studio (Upload APK to nexus)?
我正在尝试将我的 APK 上传到 Nexus 存储库。 下面的代码可以正常工作,直到我更改了 gradle 版本
从
类路径 'com.android.tools.build:gradle:2.3.3' distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip mCompileSdkVersion=23 mBuildToolsVersion='25.0.0'
到
类路径 'com.android.tools.build:gradle:3.1.0' distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip mCompileSdkVersion=27 mBuildToolsVersion='27.0.0'
更改版本后,相同的代码不起作用,我无法理解在哪里发现错误,终端未显示任何错误消息,但我的 APK 未上传到给定位置
以下是我的 App build.gradle 文件的当前配置
apply plugin: 'com.android.application'
apply plugin: 'maven'
task uploadRelease (type: Upload){
configuration = project.getConfigurations().getByName('archives');
repositories {
mavenDeployer {
repository( url: "http://XXXXXXXX:8081/nexus/XXXXXXXX/repositories/releases" ) {
authentication(userName: "MyuserName", password: "Mypassword")
}
pom.project {
version "${android.defaultConfig.versionName}"
artifactId "Collection"
name "xxxxxxxx"
groupId "com.xxxxxxxx.mobile.xxxxxxxx.collections"
}
}
}
}
task uploadSnapshot (type: Upload){
configuration = project.getConfigurations().getByName('archives');
repositories {
mavenDeployer {
repository( url: "http://XXXXXXXX:8081/nexus/XXXXXXXX/repositories/snapshots" ) {
authentication(userName: "MyuserName", password: "Mypassword")
}
pom.project {
version "${android.defaultConfig.versionName}-SNAPSHOT"
artifactId "Collection"
name "Collection"
groupId "com.xxxxxxxx.mobile.xxxxxxxx.collections"
}
}
}
}
我使用命令作为 - gradle assemblerelease uploadsnapshot
构建和上传 APK 但它不适用于 gradle 4.4 请让我知道出了什么问题
与 2.2.3 相比,新的 Android Gradle 插件版本 3.+ 将 apk 重新定位到不同的路径。
以下行可能会发生一些错误
configuration = project.getConfigurations().getByName('archives');
使用gradle assemblerelease uploadsnapshot --debug --info --stacktrace
收集更多信息并分析错误日志。
较旧的 apk 位置是
build/outputs/apk/*.apk
AGP 3.x 的 apk 位置是
build/outputs/apk/<flavour>/<buildtype>/<name>-<buildtype>.apk
所以
def apk = file('build/outputs/apk/release/iMobility-release.apk')
artifacts {
archives apk
}
这是为了用正确的 apk 位置覆盖档案的路径。
不是实际答案,但对我有用的是
把这条线放在你的下面
task uploadSnapshot (type: Upload){
configuration = project.getConfigurations().getByName('archives');
repositories {
mavenDeployer {
repository( url: "http://XXXXXXXX:8081/nexus/XXXXXXXX/repositories/snapshots" ) {
authentication(userName: "MyuserName", password: "Mypassword")
}
pom.project {
version "${android.defaultConfig.versionName}-SNAPSHOT"
artifactId "Collection"
name "Collection"
groupId "com.xxxxxxxx.mobile.xxxxxxxx.collections"
}
}
}
}
def apk = file('build/outputs/apk/release/iMobility-release.apk')
artifacts {
archives apk
}
任何人都可以解释这是为什么? 然后有更好的选择吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.