Home » Android » android – Where to place the apply Crashlytics plugin directive in Gradle build files

android – Where to place the apply Crashlytics plugin directive in Gradle build files

Posted by: admin May 14, 2020 Leave a comment

Questions:

Recently I have migrated my android project from Eclipse to Android Studio.
Currently my project has the following Gradle script structure:

  • Top-level gradle build file
  • Main module (my app) gradle build file
  • module A (my app) gradle build file
  • module B (my app) gradle build file
  • module C (my app) gradle build file

The Content of my main gradle build file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.1'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
    }
}

I would like to make sure crashlytics would be present for the whole project.
I initially tried to add

apply plugin: 'crashlytics'

to the main project gradle file, but I encountered the following error:

Error:(2, 0) Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.

I then moved the apply plugin: 'crashlytics' to the main module (my app) gradle build file and the build was successful.

Since I am new to Gradle & Android Studio, I was not sure if I need to it also to the submodules A, B, C to allow crashlytics to capture exceptions generating from those modules. Also I wonder why can’t I (or how can I) add the ” apply plugin: ‘crashlytics’ ” to the main project gradle file.

Could anyone clarify it for me?

How to&Answers: