"Duplicate class javax.inject.*" 将 Firebase Crashlytics 添加到 Android 时出现构建错误
"Duplicate class javax.inject.*" build error when Firebase Crashlytics is added to Android
我正在尝试将 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"
}
修复了错误。
我正在尝试将 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"
}
修复了错误。