Gradle Crittercism on-build mapping upload not working

182 Views Asked by At

I'm trying to upload to Crittercism on build, and I put this at the bottom of my gradle file. However, it doesn't seem to be working when I build debug. What am I doing wrong?

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

There are 2 best solutions below

0
Anup Puranik On BEST ANSWER

The way you've done it, the task that you have defined, uploadMappingToProd, will if invoked by some reason also invoke assembleDebug. Because you have asked uploadMappingToProd to depend on assembleDebug - not the reverse. Therefore assembleDebug will happily finish without getting anywhere close to uploadMappingToProd.

If you want the reverse dependency i.e. assembleDebug to depend on uploadMappingToProd then you need to add this line after defining your task.

afterEvaluate {       
    tasks.assembleDebug.dependsOn uploadMappingToProd
}

This will guarantee uploadMappingToProd is invoked everytime and before assembleDebug is invoked.

0
Soo Chun Jung On

My solution is working fine.(local build and jenkins build)

for me, only working when build is from jenkins

make sure your APPID, APPKEY, and path(release_jenkins.... normally release)

build.gradle (app) (add at the end)

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")
    }
}

sample project -> https://github.com/SinsangMarket/CrittercismMappingTXT