如何解决将 Firebase Crashlytics 添加到 Android 时出现“重复类 javax.inject.*”构建错误
我正在尝试将 Firebase Crashlytics 添加到我的项目中。我收到以下错误。
Duplicate class javax.inject.Inject found in modules javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-roboguice-3.0.1.jar (org.roboguice:roboguice:3.0.1)
Duplicate class javax.inject.Named found in modules javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-roboguice-3.0.1.jar (org.roboguice:roboguice:3.0.1)
Duplicate class javax.inject.Provider found in modules javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-roboguice-3.0.1.jar (org.roboguice:roboguice:3.0.1)
Duplicate class javax.inject.Qualifier found in modules javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-roboguice-3.0.1.jar (org.roboguice:roboguice:3.0.1)
Duplicate class javax.inject.Scope found in modules javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-roboguice-3.0.1.jar (org.roboguice:roboguice:3.0.1)
Duplicate class javax.inject.Singleton found in modules javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-roboguice-3.0.1.jar (org.roboguice:roboguice:3.0.1)
Go to the documentation to learn how to Fix dependency resolution errors.
项目级别build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用级别build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "package.name"
minSdkVersion 21
targetSdkVersion 29
versionCode 26
versionName "1.4.1"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
buildConfigField "long","TIMESTAMP",System.currentTimeMillis() + "L"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds true
// Or,if you prefer,you can continue to check for errors in release builds,// but continue the build even when errors are found:
abortOnError false
}
}
project.tasks.withType(JavaCompile) { task ->
options.compilerArgs << "-AguiceAnnotationDatabasePackageName=package"
}
dependencies {
implementation fileTree(include: ['*.jar'],dir: 'libs')
testImplementation 'junit:junit:4.12'
testImplementation project(':module1')
testImplementation 'org.mockito:mockito-core:1.+'
testImplementation('org.robolectric:robolectric:3.1-rc1') {
exclude group: 'commons-logging',module: 'commons-logging'
exclude group: 'org.apache.httpcomponents',module: 'httpclient'
}
implementation project(':module1')
implementation project(':module2')
implementation project(':roboguicehelper')
compileOnly 'org.roboguice:roboblender:3.+'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'org.roboguice:roboguice:3.+'
implementation 'com.google.android.material:material:1.0.0'
//noinspection GradleCompatible
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation project(':module4')
implementation platform('com.google.firebase:firebase-bom:26.6.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-crashlytics'
}
如果我删除它 -> implementation 'com.google.firebase:firebase-crashlytics'
项目构建并运行良好。但我需要添加 Crashlytics。
Gradle 版本是 gradle-5.6.4
有什么建议吗?
解决方法
从下图中,我们可以看到 roboguice
库中已经包含 java.inject
库。然后,Firebase Crashlytics 将 java.inject:java.inject:1@jar
添加到导致错误的库中。
在应用级别 build.gradle
中更改以下行
implementation 'com.google.firebase:firebase-crashlytics'
到
implementation ('com.google.firebase:firebase-crashlytics') {
exclude module: "javax.inject"
}
修复了错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。