android-How to solve 'gradle build running stuck in android studio when using firebase crashlytics'
1. The purpose of this post
I would demo how to solve this error when using firebase crashlytics in android studio:
When we apply the firebase crashlytics in android studio and do a run, sometimes, the android studio is stuck in ‘gradle build running’ process, and it seems that it would never ends.
I have tried these methods:
- use the gradle parallel mode
- choose the offline mode
- clean the project and restart IntelliJ IDEA
- close the internet connection
It still not work.
2. Environments
The gradle version in gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip
the build.gradle of project:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
}
}
the build.gradle of app:
apply plugin: 'io.fabric'
...
apply plugin: 'com.google.gms.google-services'
3. Debug and Solution
Build and run the app, it would stuck, click the build tab at the bottom of the IDEA window, you would see that it stuck in a process named ‘crashlyticsUploadDeobs…’, So let’s disable this task:
Open your app’s build.gradle, and add these lines at the end of your script:
afterEvaluate {
for (Task task : project.tasks.matching { it.name.startsWith('crashlyticsUploadDeobs') }) {
task.enabled = false
}
}
According to the gradle lifecycle documents, it says:
Project evaluation You can receive a notification immediately before and after a project is evaluated. This can be used to do things like performing additional configuration once all the definitions in a build script have been applied, or for some custom logging or profiling.
Here we add a listener to gradle, and check if exists some tasks whose name starts with ‘crashlyticsUploadDeobs’, if it matches, then disable it.
Clean, build and rerun the app, problem solved.