Home » Android » android – Gradle 4.1 does crashlytics upload before release build finishes

android – Gradle 4.1 does crashlytics upload before release build finishes

Posted by: admin June 15, 2020 Leave a comment

Questions:

Upgrading our dev and build environment from Android studio 2 to 3 (currently on gradle 4.1) we are running into a strange problem when running the Crashlytics APK distribution upload task. It tries to upload the APK way too early. At around the 60s mark in our build it fails with:

Uploading D:\GitRunner\path\to\release\appname-flavour1name-release.apk to Crashlytics...
 WARN - Crashlytics halted compilation because it can't find the specified file: D:\GitRunner\path\to\release\appname-flavour1name-release.apk
:appname:crashlyticsUploadDistributionFlavournameRelease FAILED

(Normal build times are around 7 mins.) I did double check the output paths of the APK and it all seems correct.

Interestingly when remoting on to the Windows build machine, and running the build command that our CI runs manually:

gradlew.bat assembleFlavour1NameRelease assembleFlavour2NameRelease appname:crashlyticsUploadDistributionFlavour1NameRelease reptile:crashlyticsUploadDistributionFlavour1NameRelease --stacktrace

it all works fine.

Eventually I have traced the bad behaviour down to the git clean that is run before the build command are run. Somehow this changes the behaviour enough to make the build pass or not.

How to&Answers:

I’ve faced the same issue. The solution with --max-workers=1 will dramatically slow down your build time if you have multiple modules in your project.

You can solve this problem by setting the order to the crashlyticsUploadDistribution task manually in your build.gradle file:

tasks.whenTaskAdded { task ->
    if (task.name == "crashlyticsUploadDistributionDebug") {
        task.dependsOn assembleDebug
    }
    if (task.name == "crashlyticsUploadDistributionRelease") {
        task.dependsOn assembleRelease
    }
}

afterEvaluate {
    crashlyticsUploadDistributionDebug.dependsOn assembleDebug
    crashlyticsUploadDistributionRelease.dependsOn assembleRelease
}

Answer:

I suspect the ordering of the gradle tasks might be off. Crashlytics seems to try and upload the APK before waiting for the build to actually complete.

Adding the gradle comandline flag: --max-workers=1 made the builds pass consistently.