Gradle example Build files for referencing Crashlytics from application projects and libraries

In connection with this post, someone has a couple of build.gradle files that demonstrate the basic setup for linking to Crashlytics from the Android library project.

I get the following error, even if I followed the recommendation provided through the message mentioned above.

This is my gradle.build application file.

buildscript { repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { classpath 'com.android.tools.build:gradle:0.10.+' classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+' } } apply plugin: 'android' apply plugin: 'crashlytics' repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { compile project(':Common.Logger') compile project(':Common.ProtocolBuffer') compile project(':Common.Utils') compile 'com.google.android.gms:play-services:+' compile 'com.android.support:support-v4:+' compile 'com.crashlytics.android:crashlytics:1.+' androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1' androidTestCompile 'junit:junit:4.11' } android { compileSdkVersion 19 buildToolsVersion '19.0.3' buildTypes { debug { buildConfigField "boolean", "USE_LOGCAT", "true" buildConfigField "boolean", "USE_CRASHLYTICS", "false" ext.enableCrashlytics=false } release { runProguard true debuggable false proguardFile getDefaultProguardFile('proguard-android-optimize.txt') buildConfigField "boolean", "USE_LOGCAT", "false" buildConfigField "boolean", "USE_CRASHLYTICS", "true" ext.enableCrashlytics=true } } sourceSets { packagingOptions { exclude 'LICENSE.txt' } lintOptions { abortOnError false } } } 

This is my current build.gradle library file.

 buildscript { repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { classpath 'com.android.tools.build:gradle:0.10.+' classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+' } } repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { compile 'com.crashlytics.android:crashlytics:1.+' } apply plugin: 'android-library' android { compileSdkVersion 19 buildToolsVersion '19.0.3' buildTypes { debug { buildConfigField "boolean", "USE_LOGCAT", "true" buildConfigField "boolean", "USE_CRASHLYTICS", "false" ext.enableCrashlytics=false } release { buildConfigField "boolean", "USE_LOGCAT", "false" buildConfigField "boolean", "USE_CRASHLYTICS", "true" ext.enableCrashlytics=true } } sourceSets { lintOptions { abortOnError false } } } 

Some time ago Crashlytics told me to just use the ext.enableCrashlytics flag in the buildType file.

The following is the current gradle error that occurs using gradle assembly files.

 Error:A problem occurred configuring root project 'ManageMyVMail.Android'. > A problem occurred configuring project ':Common.ProtocolBuffer'. > Could not resolve all dependencies for configuration ':Common.ProtocolBuffer:_debugCompile'. > Could not find any version that matches com.crashlytics.android:crashlytics:1.+. Required by: ManageMyVMail.Android:Common.ProtocolBuffer:unspecified > ManageMyVMail.Android:Common.Logger:unspecified 

As a side issue, I need to create the same set of buildConfigField values ​​in both files if I want to use them from both projects after I pass the current gradle build error. I am new to gradle and Android Studio, but the Intertron search just didn't give an answer.

Thanks in advance.

+6
source share
1 answer

After a few emails with Crashlytics support, I found a solution. There were two aspects to the final decision.

  • The error message posted earlier indicated the situation, I just did not read it correctly. Simply, a library project that did not need Crashlytics depended on another library project that really needed Crashlytics. Adding a Crashlytics dependency to the above library solves the Gradle build problem.

  • The Crashlytics API key should have been added to the library project manifest, depending on Crashlytics. The project was built, but my log messages were not sent at runtime, so this was an explicit fix after I established the connection.

I included Gradle files from each of the (3) projects involved in my script. Hope this helps others and thanks to Mike at Crashlytics for replying to my posts.

App.gradle ( calls Crashlytics.start () )

 buildscript { repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { classpath 'com.android.tools.build:gradle:0.10.+' classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+' } } apply plugin: 'android' apply plugin: 'crashlytics' repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { compile project(':Common.Logger') compile project(':Common.ProtocolBuffer') compile project(':Common.Utils') compile 'com.google.android.gms:play-services:+' compile 'com.android.support:support-v4:+' compile 'com.crashlytics.android:crashlytics:1.+' androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1' androidTestCompile 'junit:junit:4.11' } android { compileSdkVersion 19 buildToolsVersion "19.1.0" buildTypes { debug { buildConfigField "boolean", "USE_CRASHLYTICS", "false" } release { buildConfigField "boolean", "USE_CRASHLYTICS", "true" runProguard true debuggable false proguardFile getDefaultProguardFile('proguard-android-optimize.txt') } } sourceSets { packagingOptions { exclude 'LICENSE.txt' } lintOptions { abortOnError false } } } 

Common.Logger.gradle ( calls Crashlyics.log () )

 apply plugin: 'android-library' repositories { maven { url 'http://download.crashlytics.com/maven' } } dependencies { compile 'com.crashlytics.android:crashlytics:1.+' } android { compileSdkVersion 19 buildToolsVersion "19.1.0" buildTypes { debug { ext.enableCrashlytics = false } release { ext.enableCrashlytics = true } } sourceSets { lintOptions { abortOnError false } } } 

Common.ProtocolBuffer.gradle ( depends on Common.Logger, no Crashlytics calls )

 apply plugin: 'android-library' repositories { mavenCentral() maven { url 'http://download.crashlytics.com/maven' } } dependencies { compile 'com.google.protobuf:protobuf-java:2.4.1' compile 'org.apache.commons:commons-io:1.3.2' compile 'com.crashlytics.android:crashlytics:1.+' compile project(':Common.Logger') } android { compileSdkVersion 19 buildToolsVersion "19.1.0" sourceSets { lintOptions { abortOnError false } } } 
+6
source

Source: https://habr.com/ru/post/969706/


All Articles