6

参考这篇文章,是否有人有一对 build.gradle 文件来演示从 android 库项目中引用 Crashlytics 的基本设置?

即使我遵循了上面最初提到的帖子提供的建议,我也会收到以下错误。

这是我的 App gradle.build 文件。

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
        }
    }
}

这是我当前的库 build.gradle 文件。

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
        }
    }
}

不久前,Crashlytics 支持人员告诉我,只需在 buildType 中使用“ext.enableCrashlytics”标志即可。

以下是使用上述 gradle 构建文件时出现的当前 gradle 错误。

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

作为第二个问题,如果我想在通过当前的 gradle 构建错误后从两个项目中使用它们,是否需要在两个文件中创建相同的 buildConfigField 值集。我对 Gradle 和 Android Studio 还很陌生,但是搜索 Intertron 还没有得到答案。

先感谢您。

4

1 回答 1

6

在收到 Crashlytics 支持的几封电子邮件后,我找到了解决方案。最终解决方案有两个方面。

  1. 最初发布的错误消息是说明情况,我只是没有正确阅读它。简单地说,不需要 Crashlytics 的库项目依赖于另一个确实需要 Crashlytics 的库项目。将 Crashlytics 依赖项添加到上述库解决了 Gradle 构建问题。

  2. 必须根据 Crashlytics 将 Crashlytics API 密钥添加到库项目清单中。该项目已构建,但没有在运行时提交我的“日志”消息,因此一旦我建立连接,这就是一个明显的修复。

我已经包含了我的场景中涉及的每个 (3) 项目的 Gradle 文件。希望这对其他人有所帮助,并感谢 Crashlytics 的 Mike 回复我的消息。

App.gradle(调用 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(调用 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(依赖于 Common.Logger,没有 Crashlytics 调用

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
        }
    }
}
于 2014-06-18T15:16:20.900 回答