eopeter / flutter_mapbox_navigation

Turn By Turn Navigation for Your Flutter Application
Apache License 2.0
217 stars 185 forks source link

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. #375

Closed muhammadnaqeeb closed 2 months ago

muhammadnaqeeb commented 2 months ago

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")

}

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
  get: ^4.6.6
  firebase_core: ^2.24.2
  firebase_auth: ^4.16.0
  cloud_firestore: ^4.14.0
  firebase_storage: ^11.7.7
  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
  flutter_mapbox_navigation: ^0.2.2

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0
Arshad-ullah commented 2 months ago

Yes, I also faced this issue. Just downgrade the mapbox version.

flutter_mapbox_navigation: ^0.2.2 mapbox_maps_flutter: ^0.6.0

muhammadnaqeeb commented 2 months ago

@Arshad-ullah, thank you so much for your help. I've been struggling for the past few days. Thanks!

SalmanNaghori commented 2 months ago

@Arshad-ullah The duplication error is resolved, but it now shows a lifecycle error when running.