It usually happens when you import libraries which uses java packages which conflict with android packages of the same name.
Duplicate class com.google.api.client.http.apache.ApacheHttpRequest found in modules google-http-client-1.29.1.jar (com.google.http-client:google-http-client:1.29.1) and google-http-client-apache-2.0.0.jar (com.google.http-client:google-http-client-apache:2.0.0)
Usually the solution involve removing packages from libraries which uses the conflicting java library
Edit Module:app build.gradle
dependencies {
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
}
If you are unsure which libraries is causing the problem
android {
configurations {
implementation.exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
}
Sometimes the Android implementation and Java implementation differs greatly, such as protobuf-lite
and protobuf-java
. Excluding either one packages could solve compilation error, but you will bump into runtime error when the underlying implementation is not found.