Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Program type already present: com.google.common.annotations.Beta

Since my android studio updated a couple of days ago, I have been struggling to get my application running again due to this error.

Program type already present: com.google.common.annotations.Beta    
Message{kind=ERROR, text=Program type already present: 
com.google.common.annotations.Beta, sources=[Unknown source file], tool name=Optional.of(D8)}

Here is my build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.dissertation.bitcoin.bitparking"
    minSdkVersion 21
    targetSdkVersion 27
    multiDexEnabled true
    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(include: ['*.jar'], dir: 'libs')
implementation('com.android.support:appcompat-v7:27.1.0')
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
implementation 'com.google.api-client:google-api-client-android:1.23.0'
implementation 'com.google.code.findbugs:jsr305:2.0.1'
implementation 'com.google.api-client:google-api-client-gson:1.23.0'
implementation 'com.googlecode.json-simple:json-simple:1.1'
implementation files('libs/java-json.jar')
implementation 'com.android.support:support-compat:27.1.0'
implementation 'com.github.bumptech.glide:glide:4.3.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google:bitcoinj:0.11.3'
implementation 'de.schildbach.wallet:integration-android:2.0'
}

This code was working fine for me last week. However as I am fairly new to android development, I may have overlooked something. Any help would be appreciated, thank you.

like image 967
Peter Barnes Avatar asked Mar 28 '18 17:03

Peter Barnes


4 Answers

Just try add exclude module: 'guava-jdk5' to google apis imports like this:

implementation('com.google.api-client:google-api-client-android:1.20.0') {
    exclude module: 'guava-jdk5'
}
like image 101
Paul Grynyk Avatar answered Nov 10 '22 23:11

Paul Grynyk


If all fails, try:

[app/build.gradle]

configurations {
    all*.exclude module: 'guava-jdk5' 
}
like image 26
Mickey Mouse Avatar answered Nov 11 '22 00:11

Mickey Mouse


As for my case, I'm using google-api-services-tasks and google-api-client-android. By checking the dependencies, I noticed that they both use google-api-client.

./gradlew app:dependencies

...
+--- com.google.api-client:google-api-client-android:1.23.0
|    +--- com.google.api-client:google-api-client:1.23.0
|    |    +--- com.google.oauth-client:google-oauth-client:1.23.0
|    |    |    +--- com.google.http-client:google-http-client:1.23.0
|    |    |    |    +--- com.google.code.findbugs:jsr305:1.3.9 -> 2.0.1
|    |    |    |    \--- org.apache.httpcomponents:httpclient:4.0.1
|    |    |    |         +--- org.apache.httpcomponents:httpcore:4.0.1
|    |    |    |         +--- commons-logging:commons-logging:1.1.1
|    |    |    |         \--- commons-codec:commons-codec:1.3
|    |    |    \--- com.google.code.findbugs:jsr305:1.3.9 -> 2.0.1
|    |    +--- com.google.http-client:google-http-client-jackson2:1.23.0
|    |    |    +--- com.google.http-client:google-http-client:1.23.0 (*)
|    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.1.3
|    |    \--- com.google.guava:guava-jdk5:17.0
|    \--- com.google.http-client:google-http-client-android:1.23.0
|         \--- com.google.http-client:google-http-client:1.23.0 (*)
+--- com.google.apis:google-api-services-tasks:v1-rev52-1.23.0
|    \--- com.google.api-client:google-api-client:1.23.0 (*)

Once I excluded guava-jdk5 from both, the error message went away.

[app/build.gradle]

implementation('com.google.api-client:google-api-client-android:1.23.0') {
    exclude module: 'guava-jdk5'
}
implementation('com.google.apis:google-api-services-tasks:v1-rev52-1.23.0') {
    exclude module: 'guava-jdk5'
}
like image 2
solamour Avatar answered Nov 10 '22 22:11

solamour


Change Gradles To This:

implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'  exclude module: 'guava-jdk5'
    implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'guava-jdk5' exclude module: 'httpclient'
    implementation 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'

It Worked For Me

like image 2
Harshil Patel Avatar answered Nov 10 '22 23:11

Harshil Patel