Gradle Crittercism 构建映射上传不工作

Gradle Crittercism on-build mapping upload not working

我试图在构建时上传到 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'
}

按照您完成它的方式,您定义的任务 uploadMappingToProd如果由于某种原因被调用 也会调用 assembleDebug。因为您已经要求 uploadMappingToProd 依赖于 assembleDebug - 而不是相反。因此 assembleDebug 将愉快地完成而不会接近 uploadMappingToProd.

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

afterEvaluate {       
    tasks.assembleDebug.dependsOn uploadMappingToProd
}

这将保证 uploadMappingToProd 被调用 每次 before assembleDebug 被调用。

我的解决方案运行良好。(本地构建和 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")
    }
}

示例项目 -> https://github.com/SinsangMarket/CrittercismMappingTXT