Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android studio中发布gradle 4.4中的工件(将APK上传到nexus)?_Android_Android Studio_Gradle_Upload_Snapshot - Fatal编程技术网

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

如何在android studio中发布gradle 4.4中的工件(将APK上传到nexus)?,android,android-studio,gradle,upload,snapshot,Android,Android Studio,Gradle,Upload,Snapshot,我正在尝试将我的APK上载到Nexus存储库。 下面的代码在我更改gradle版本之前可以正常工作 从 classpath'com.android.tools.build:gradle:2.3.3' 分配=https://services.gradle.org/distributions/gradle-3.3-all.zip mCompileSdkVersion=23 mBuildToolsVersion='25.0.0' 至 classpath'com.android.tools.build:

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

classpath'com.android.tools.build:gradle:2.3.3' 分配=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' 分配=https://services.gradle.org/distributions/gradle-4.4-all.zip mCompileSdkVersion=27 mBuildToolsVersion='27.0.0'

更改版本后,相同的代码不起作用,我无法理解在哪里发现错误,终端未显示任何错误消息,但我的APK未上载到给定位置

以下是my 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"
            }
        }
    }
}
我使用命令作为-
gradleassembleerelease uploadsnapshot


要构建和上传APK,但它不适用于gradle 4.4,请告诉我新的Android gradle插件版本3出了什么问题。+将APK重新定位到与2.2.3不同的路径

以下行可能会出现一些错误

configuration = project.getConfigurations().getByName('archives');
使用
gradle assembleerelease uploadsnapshot--debug--info--stacktrace
收集更多信息并分析错误日志

较旧的apk位置为

build/outputs/apk/*.apk
AGP3.x的apk位置为

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

这是为了用正确的apk位置覆盖归档文件的路径

不是真正的答案,而是对我有用的东西

把这条线放在你的下面

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
}

有人能解释为什么吗?还有一个比这个更好的选项?

使用
gradle assemblererelease uploadsnapshot--debug--info--stacktrace
来收集更多信息并发布错误日志。我使用这个命令得到了错误日志,比如“由于上述错误而失败”,当我使用这个--------def apk=file时,上面没有任何错误('build/outputs/apk/release/iMobility release.apk')工件{archives apk}它对我有用,但不知道为什么从AGP 3.0+开始,apk位置根据构建变量放置在路径中,例如outputs/apk//iMobility release.apk',这与旧的2.x+版本不同。
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
}