简体   繁体   English

如何在android studio的gradle 4.4中发布工件(将APK上传到nexus)?

[英]How to publish artifacts in gradle 4.4 in android studio (Upload APK to nexus)?

I am trying to upload my APK to Nexus repository.我正在尝试将我的 APK 上传到 Nexus 存储库。 Below code work fine until I have change gradle version下面的代码可以正常工作,直到我更改了 gradle 版本

from

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'类路径 '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'

To

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'类路径 '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'

After changing versions same code is not work I am not able to understand where I found an error, Terminal not showing any error message but my APK is not uploaded in given location更改版本后,相同的代码不起作用,我无法理解在哪里发现错误,终端未显示任何错误消息,但我的 APK 未上传到给定位置

following is the current configuration of my App build.gradle file以下是我的 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"
            }
        }
    }
}

I use Command as - gradle assemblerelease uploadsnapshot我使用命令作为 - gradle assemblerelease uploadsnapshot

to build and upload APK but It does not work for gradle 4.4 Please let me know what went wrong构建和上传 APK 但它不适用于 gradle 4.4 请让我知道出了什么问题

The new Android Gradle Plugin version 3.+ relocate the apk to a different paths compared to 2.2.3.与 2.2.3 相比,新的 Android Gradle 插件版本 3.+ 将 apk 重新定位到不同的路径。

Some errors may happen at below line以下行可能会发生一些错误

configuration = project.getConfigurations().getByName('archives');

Use gradle assemblerelease uploadsnapshot --debug --info --stacktrace to gather more information and analyse the error logs.使用gradle assemblerelease uploadsnapshot --debug --info --stacktrace收集更多信息并分析错误日志。

The older apk location is较旧的 apk 位置是

build/outputs/apk/*.apk

the apk location for AGP 3.x is AGP 3.x 的 apk 位置是

build/outputs/apk/<flavour>/<buildtype>/<name>-<buildtype>.apk 

so所以

def apk = file('build/outputs/apk/release/iMobility-release.apk')
artifacts {
    archives apk
}

This is to overwrite the paths of archives with the correct apk location.这是为了用正确的 apk 位置覆盖档案的路径。

Not the actual answer but what work for me is不是实际答案,但对我有用的是

Put this line below your把这条线放在你的下面

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
}

Can any one explain this why ?任何人都可以解释这是为什么? and have a better option then this ?然后有更好的选择吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM