Where to put the applicable Crashlytics plugin directive in Gradle build files

I recently migrated my android project from Eclipse to Android Studio. My project currently has the following Gradle script structure:

  • Gradle Top Level Assembly File
  • Main module (my application) Gradle build file
  • module A (my application) Gradle build file
  • module B (my application) Gradle build file
  • C module (my application) Gradle build file

The contents 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 that starches will be presented for the entire project. At first I tried to add

 apply plugin: 'crashlytics' 

to the main Gradle project file, but I found the following error:

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

Then I moved the apply plugin: 'crashlytics' to the build module assembly file (my application) Gradle, and the build was successful.

Since I am new to Gradle and Android Studio, I was not sure I needed this also for submodules A, B, C to allow crashlytics to catch exceptions thrown from these modules. I am also wondering why I can’t (or how I can) add "apply plugin:" crashlytics "to the main Gradle project file.

Can anyone clarify this for me?

+5
source share
1 answer

An exception from the submodule (library module, not the application module) will be reported if the main application failure . If it does the right thing and does not fail, nothing is reported.

In general, you are changing the application (submodule) build.gradle . Sometimes you need to change the top level of gradle to add common dependencies.

Appli Plugin:
You cannot apply the plugin to the top level gradle, like the gradle project, and not the gradle module. Not sure about that.

Note:
Twitter bought Crashlytics and integrated it into Fabric . I recommend you use the Fabric plugin, which will allow you to have some statistics in a really nice interface. It also supports iOS and Android on the same disc, with bot support (Jira, etc.).

If you are using Fabric, the app gradle build file will look like this:

 buildscript { repositories { maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: 'com.android.application' apply plugin: 'io.fabric' ... dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) ... compile('com.crashlytics.sdk.android:crashlytics: 2.2.2@aar ') { transitive = true; } } 
0
source

All Articles