【问题标题】:How to publish artifacts in gradle 4.4 in android studio (Upload APK to nexus)?如何在 android studio 中发布 gradle 4.4 中的工件(将 APK 上传到 nexus)?
【发布时间】:2019-02-02 22:12:41
【问题描述】:

我正在尝试将我的 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 请让我知道出了什么问题

【问题讨论】:

  • 使用gradle assemblerelease uploadsnapshot --debug --info --stacktrace 收集更多信息并发布错误日志。

标签: android android-studio gradle upload snapshot


【解决方案1】:

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

【讨论】:

  • 我用这个命令得到了错误日志,比如“由于上述错误而失败”,上面没有任何错误
  • 当我使用这个时------------def apk = file('build/outputs/apk/release/iMobility-release.apk') artifacts { archives apk它对我有用,但不知道为什么
  • 从 AGP 3.0+ 开始,apk 位置根据构建变体放置到路径中,例如output/apk//iMobility-release.apk',与旧的 2.x+ 版本不同。
【解决方案2】:

不是真正的答案,但对我有用的是

把这条线放在你的下面

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
}

谁能解释一下这是为什么?还有比这个更好的选择吗?

【讨论】:

    猜你喜欢
    • 2018-09-21
    • 1970-01-01
    • 2015-01-31
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    相关资源
    最近更新 更多