I’m encountering an error in my Flutter project while trying to build the app. The error seems to be related to duplicate classes in the Mapbox SDK. I am using mapbox_maps_flutter and flutter_mapbox_navigation both.
Error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class com.mapbox.common.module.okhttp.CallbackWrapper found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.CallbackWrapper$RequestCallback found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.HttpCallback found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.IdGenerator found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.LazyClient found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.MapboxOkHttpService found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.MapboxOkHttpService$1 found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.MapboxOkHttpService$HttpServiceGetLifecycleStateCallback found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.MapboxOkHttpService$HttpServiceLifecycleObserver found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.MapboxOkHttpService$HttpServiceOfflineSwitchObserver found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.MapboxOkHttpService$QueuedRequest found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.NetworkUsageListener found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Duplicate class com.mapbox.common.module.okhttp.NetworkUsageListener$NetworkUsageMetricCallback found in modules jetified-common-24.5.0-runtime (com.mapbox.common:common:24.5.0) and jetified-okhttp-23.8.0-runtime (com.mapbox.common:okhttp:23.8.0)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
build.gragle:android
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = "../build"
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
build.gragle:app
plugins {
id "com.android.application"
// START: FlutterFire Configuration
id 'com.google.gms.google-services'
// END: FlutterFire Configuration
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
flutterVersionCode = "1"
}
def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
flutterVersionName = "1.0"
}
android {
namespace = "com.example.nursing_application"
compileSdk = 34
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.nursing_application"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = 21
targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger()
versionName = flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
}
}
}
flutter {
source = "../.."
}
dependencies {
implementation platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")
}
gradle.properties
org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
SDK_REGISTRY_TOKEN=sk.XXX
MAPBOX_DOWNLOADS_TOKEN=sk.XXX
settings.gradle
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
// END: FlutterFire Configuration
id "org.jetbrains.kotlin.android" version "2.0.0" apply false
}
include ":app"
pubspec.yaml
name: nursing_application
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.4.3 <4.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
flutter_screenutil: 5.9.0
flexify: ^2.0.2
get: ^4.6.6
google_fonts: ^6.2.1
otp_text_field: ^1.1.1
flutter_svg: ^2.0.10+1
toastification: ^2.0.0
firebase_core: ^2.24.2
firebase_auth: ^4.16.0
cloud_firestore: ^4.14.0
intl: ^0.19.0
uuid: ^4.4.2
cached_network_image: ^3.3.1
image_picker: ^1.1.2
firebase_storage: ^11.7.7
flutter_dotenv: ^5.1.0
latlong2: ^0.9.1
location: ^7.0.0
location_picker_flutter_map: ^3.0.1
mapbox_maps_flutter: ^2.1.0
permission_handler: ^11.3.1
http: ^1.2.2
loading_animation_widget: ^1.2.1
flutter_mapbox_navigation: ^0.2.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0
flutter:
uses-material-design: true
Cleaned and rebuilt the project.
Clean Caches
Do something like this (suggested by chatgpt)
dependencies {
implementation 'com.mapbox.common:common:24.5.0'
implementation ('com.mapbox.common:okhttp:23.8.0') {
exclude group: 'com.mapbox.common', module: 'common'
}
}