首页 > 解决方案 > 如何在 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 请让我知道出了什么问题

标签: androidandroid-studiogradleuploadsnapshot

解决方案


与 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 位置覆盖档案的路径。


推荐阅读