如何在Android Studio中的Gradle 4.4中发布工件(将APK上传到关联)?

时间:2018-08-28 10:00:11

标签: android android-studio gradle upload snapshot

我正在尝试将APK上传到Nexus存储库。 下面的代码可以正常工作,直到我更改了gradle版本

来自

  

classpath'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'

收件人

  

classpath'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"
            }
        }
    }
}

我将Command用作-gradle assemblerelease uploadsnapshot

构建和上传APK,但不适用于gradle 4.4,请让我知道发生了什么问题

2 个答案:

答案 0 :(得分:1)

新的Android Gradle插件版本3. +将APK重新定位到与2.2.3相比不同的路径。

下面的行可能会发生一些错误

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

答案 1 :(得分:0)

不是实际答案,但对我有用的是

将此行放在您的

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
}

有人可以解释为什么吗?还有一个更好的选择呢?