我是Android Studios和Gradle的新手,所以如果这个问题很明显,我想道歉。
使用给定的代码时出现以下错误:
Error: Program type already present: javax.inject.Inject
apply plugin: 'com.android.application'
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 28
defaultConfig {
applicationId "com.example.xxx.cryptoapp"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'android.arch.lifecycle:extensions:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.lucadev:coinmarketcap-api:2.1'
}
希望您能帮助我。 :)
修改
我研究了依赖关系,发现javax.inject
被使用了两次:
//short version of the list
+--- org.glassfish.hk2.external:javax.inject:2.5.0-b42@jar
+--- com.fasterxml.jackson.core:jackson-core:2.8.4@jar
\--- javax.inject:javax.inject:1@jar
但是我不太了解如何排除正确的模块。
答案 0 :(得分:0)
假设这来自.jar
目录中的libs
文件;可以像这样被排除在外:
implementation (fileTree(dir: "libs", include: ["*.jar"])) {
exclude group: "javax.inject", module: "javax.inject"
}
实际上,.jar
应该应该被删除并替换为:
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
implementation ("com.fasterxml.jackson.core:jackson-core:2.9.8") {
exclude group: "javax.inject", module: "javax.inject"
}
此存储库为mavenCentral()
。