参考这个
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","false" buildConfigField "boolean","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","false" ext.enableCrashlytics=false } release { buildConfigField "boolean","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
作为第二个问题,我是否需要在两个文件中创建相同的buildConfigField值集合,如果我想在通过当前的gradle构建错误后从两个项目中使用它们.我对Gradle和Android Studio相当新,但是搜索Intertron还没有得到答案.
先感谢您.
解决方法
在收到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","false" } release { buildConfigField "boolean","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 } } }