2

I'm pretty new to Android Studios and Gradle, so if this question is something obvious I'd like to apologize.

I get the following error with the given code:

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'
}

I hope you can help me out. :)

Edit

I looked into the dependencies and saw that javax.inject is used two times:

//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

However I can't quite understand how I exclude the correct module..

bloodipwn
  • 31
  • 5
  • can you post the full stracktrace? – Jorge Gil Dec 28 '18 at 22:36
  • check https://stackoverflow.com/questions/49112190/error-program-type-already-present-android-support-design-widget-coordinatorl you need to check dependencies. There might be some conflict. or else write exclusion policy on modules – Shubham AgaRwal Dec 28 '18 at 22:41
  • Possible duplicate of [What does "Program type already present" mean?](https://stackoverflow.com/questions/49676155/what-does-program-type-already-present-mean) – Shubham AgaRwal Dec 28 '18 at 22:42
  • (One way to make a quote stand out is to use not apostrophes, but `\`\`` "backticks" like `Error: Program type already present: javax.inject.Inject`. The other is to put it in a separate line and prefix it with `> ` (or use the "quote button" in the post editor).) – greybeard Dec 28 '18 at 22:57
  • I tried adding the support dependency `implementation 'com.android.support:design:28.0.0'` but without success.. – bloodipwn Dec 30 '18 at 16:02
  • 1
    I found out what the problem seems to be, thanks @Killer - However javax.inject seems to be used by two dependencies and i want to exclude it from one, but I don't know where it comes from. `+--- com.fasterxml.jackson.core:jackson-core:2.8.4@jar
    \--- javax.inject:javax.inject:1@jar`
    – bloodipwn Dec 30 '18 at 16:25

1 Answers1

0

assuming this is coming from a .jar file in the libs directory; it can be excluded alike this:

implementation (fileTree(dir: "libs", include: ["*.jar"])) {
    exclude group: "javax.inject", module: "javax.inject"
}

while actually, the .jar should probably be just deleted and replaced with:

// 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"
}

the repository for this is mavenCentral().

Nick Chapsas
  • 6,872
  • 1
  • 20
  • 29
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • 1
    Your first suggestion throws as follows: `Gradle sync failed: Could not find method exclude() for arguments [{group=javax.inject, module=javax.inject}] on object of type org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency. Consult IDE log for more details (Help | Show Log) (266 ms)` Your second suggestion compiled but I still hat the same error with javax.inject .. – bloodipwn Dec 30 '18 at 18:53