Gradle Crittercism on-build映射上传不起作用

时间:2016-11-14 22:18:11

标签: android gradle groovy crittercism

我正在尝试在构建时上传到Crittercism,我把它放在gradle文件的底部。但是,当我构建调试时,它似乎不起作用。我做错了什么?

task uploadMappingToProd() << {
    def critterAppId = "abcde"
    def appVersionName = "1.0.1"
    def appVersionCode = "DEBUG"
    def critterKey = "12345"

    commandLine 'curl',
            "https://app.crittercism.com/api_beta/proguard/$critterAppId",
            '-F', 'proguard=@build/outputs/mapping/production/release/mapping.txt',
            '-F', "app_version=$appVersionName-$appVersionCode",
            '-F', "key=$critterKey"

    type Exec
    dependsOn 'assembleDebug'
}

2 个答案:

答案 0 :(得分:1)

您完成此操作的方式,您已定义的任务uploadMappingToProd,如果因某种原因调用 ,也会调用assembleDebug。因为您已经要求uploadMappingToProd依赖assembleDebug - 而不是相反。因此,assembleDebug将很快完成,而不会接近uploadMappingToProd

如果您希望反向依赖,即assembleDebug依赖于uploadMappingToProd,那么您需要在定义任务后添加此行。

afterEvaluate {       
    tasks.assembleDebug.dependsOn uploadMappingToProd
}

这样可以保证在调用 uploadMappingToProd之前每次调用调用

答案 1 :(得分:0)

我的解决方案工作正常。(本地构建和jenkins构建)

对我来说,只有在构建来自jenkins时才能工作

确保您的APPID,APPKEY和路径(release_jenkins ....正常发布)

build.gradle(app)(最后添加)

task uploadPro << {
    logger.error("Uploading mapping.txt file to crittercism")
    String temp = projectDir;
    temp = temp.replace("\\", "/");
    String[] cmd = ["curl", "-k", "https://app.crittercism.com/api_beta/proguard/AppIDSting",
                 "-F", "proguard=@" + temp + "/build/outputs/mapping/release_jenkins/mapping.txt",
                 "-F", "app_version=" + VERSION_NAME + '-' + VERSION_CODE,
                 "-F", "key=API_KEY"]
    logger.error("CMD : " + cmd)
    ProcessBuilder builder = new ProcessBuilder(cmd);
    Process process = builder.start();
    process.waitFor()
    println process.err.text
    println process.text
    }

gradle.buildFinished {
    //check your build type. I am not sure it's the best way to do it.
    logger.error("JSC : 이름 ! - " + gradle.startParameter.taskNames);
    if (gradle.startParameter.taskNames.contains("assembleRelease_jenkins")) {
        logger.error("JSC : 올리기 시작 ! - " + gradle.startParameter.taskNames);
        tasks.uploadPro.execute()
    } else {
        logger.error("JSC : PASS")
    }
}

示例项目 - &gt; https://github.com/SinsangMarket/CrittercismMappingTXT