参考这个post,有没有人有一对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
}
}
}
这是我当前的Library 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支持我告诉我,只需使用“ext.enableCrashlytics”' buildType中的标志。
以下是使用上述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
作为第二个问题,我是否需要在两个文件中创建相同的buildConfigField值,如果我想在我超过当前的gradle构建错误后从两个项目中使用它们。我对Gradle和Android Studio相当新,但是搜索Intertron还没有得到答案。
提前谢谢。
答案 0 :(得分:6)
在收到Crashlytics支持的几封电子邮件后,我找到了解决方案。最终解决方案有两个方面。
最初发布的错误消息是陈述情况,我只是没有正确阅读。简单地说,不需要Crashlytics的图书馆项目取决于其他需要Crashlytics的图书馆项目。将Crashlytics依赖项添加到上述库中解决了Gradle构建问题。
必须根据Crashlytics将Crashlytics API密钥添加到库项目清单中。该项目已构建,但未在运行时提交我的“日志”消息,因此一旦建立连接,这是一个明显的修复。
我已经包含了我的方案中涉及的每个(3)项目中的Gradle文件。希望这有助于其他人,并感谢Mike在Crashlytics回复我的消息。
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
}
}
}