Execution failed for task ‘:app ‘ in Flutter project with Mapbox

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật