Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example gradle build files for referencing Crashlytics from App and Library projects

In reference to this post, does anyone have a pair of build.gradle files that demonstrate the basic setup for referencing Crashlytics from a android library project?

I get the following error even though I followed the recommendation provided via the post originally mentioned above.

This is my App gradle.build 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 Library build.gradle 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
        }
    }
}

I was told by Crashlytics support some time ago to simply use the 'ext.enableCrashlytics' flag in a buildType.

The following is the current gradle error that occurs using the above gradle build 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 secondary question, do I need to create the same set of buildConfigField values in both files if I want to use them from both projects after I get past the current gradle build error. I am fairly new to Gradle and Android Studio, but searching the Intertron just has not produced an answer yet.

Thank you in advance.

like image 712
Brian Butterfield Avatar asked May 22 '14 15:05

Brian Butterfield


1 Answers

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

  1. The error message originally posted was stating the situation, I was just not reading it correctly. Simply, the library project that did not need Crashlytics depended on the other library project that did need Crashlytics. Adding the Crashlytics dependency to the aforementioned library solved the Gradle build issue.

  2. The Crashlytics API key had to be added to the library project manifest depending on Crashlytics. The project built, but did not submit my "log" messages at runtime, so this was an obvious fix once I made the connection.

I have included the Gradle files from each of the (3) projects involved in my scenario. Hope this helps others and thanks to Mike at Crashlytics for responding to my messages.

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
        }
    }
}
like image 110
Brian Butterfield Avatar answered Oct 18 '22 18:10

Brian Butterfield