android - 如何在 android studio 中发布 gradle 4.4 中的工件(将 APK 上传到 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 位置覆盖档案的路径。
推荐阅读
- html - Angular ng-select 多选复选框
- java - java中匹配字符串所需的正则表达式模式以“{{”开头并以“}}”结尾
- css - 如何将动态 TailwindCSS 类添加到 React 中的 DOM 元素
- reactjs - 一次向地图状态对象添加值
- haskell - Haskell 用新书替换给定的现有书
- python - 通过 init kwargs 向对象添加属性
- laravel - 如果不用于令牌,Sanctum 和 Laravel 的默认身份验证是否相同?
- angular - 获取文档 ID Firestore 角度
- c# - HTTP GET 返回二进制而不是文本
- python - Python Kivy 在 Popup 内的按钮之间切换