Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 4.1 does crashlytics upload before release build finishes

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.

like image 255
Diederik Avatar asked Feb 06 '18 07:02

Diederik


2 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
}
like image 88
c0nst Avatar answered Oct 24 '22 10:10

c0nst


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.

like image 30
Diederik Avatar answered Oct 24 '22 11:10

Diederik