Search code examples
androidgradlemapboxmapbox-android

Program type already present: com.mapbox.android.core.location.GoogleLocationEngine


I'm trying to use Mapbox together with google play services location.

Everything worked fine until I added implementation 'com.google.android.gms:play-services-location:16.0.0' to be able to request location updates when app in background.

Gradle builds fine but when compiling the project I get the following error:

....
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: com.mapbox.android.core.location.GoogleLocationEngine$1$2
at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:116)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:74)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:59)
... 57 more

I had a similar problem before and I was able to exclude the library causing the issue. However, with Mapbox I can't figure out how to resolve this conflict.

What I tried:

implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:6.8.0'){
    exclude group: "com.google.android.gms", module: "play-services-location"
} // Probably will have no effect as this module doesn't seem to be a dependency of Mapbox

OR

implementation ('com.google.android.gms:play-services-location:16.0.0'){
    force = true
}

Any help would be appreciated.

EDIT: Trying the version 7.0.0 beta2 of Mapbox seems to solve the issue, but I would like to avoid using a beta version in prod, so if there is any way I can make the current version of Mapbox with google play services location it will be great


Solution

  • Add android location services :

    implementation 'com.google.android.gms:play-services-location:16.0.0'
    

    At the end of build.gradle(app level) after dependencies close section add this line :

    apply plugin: 'com.google.gms.google-services'
    

    Like this :

        dependencies {
           ...
           implementation 'com.google.android.gms:play-services-location:16.0.0'
        }
        apply plugin: 'com.google.gms.google-services'