Flutter에서 MapBox 사용하기, Flutter with MapBox

이번 프로젝트에서는 맵 기능에 MapBox 라이브러리를 사용하기로 하였습니다.

Flutter library 는 가장 많이 사용되고 있는 mapbox_gl 을 사용하기로 했습니다.

https://pub.dev/packages/mapbox_gl

 

MapBox를 사용하기 위해 회원 가입을 하면 아래 이미지와 같은 화면이 보이게 됩니다.

 

하단에 보이는 Create a token 버튼을 통해 Access token을 발급 받아야 합니다. 

Android guide (https://docs.mapbox.com/android/maps/guides/install/)에 의하면 Download:Read scope를 설정해줘야한다고 하니 체크를 하고 이름을 주고 생성해보았습니다.

 

 

저는 안드로이드에서 테스트를 하려고 했기 때문에 Android guide (https://docs.mapbox.com/android/maps/guides/install/)를 보면서 설정하고 있었는데 하나씩 따라하다보니 아래와 같은 에러가 발생했습니다.

해당 에러는 Class가 중복 선언되었다는것이라서 MapBox 가이드 중 app/build.gradle 파일의 디펜던시를 제거해주었습니다.

implementation 'com.mapbox.maps:android:10.12.1' <<  이 항목을 제거해 주면 아래 에러들이 해결됩니다.

Launching lib/main.dart on SM N950N in debug mode...
Running Gradle task 'assembleDebug'...

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.android.core.location.LocationEngine found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.location.LocationEngineCallback found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.location.LocationEngineProvider found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.location.LocationEngineRequest found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.location.LocationEngineRequest$1 found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.location.LocationEngineRequest$Builder found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.location.LocationEngineResult found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.permissions.PermissionsListener found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.permissions.PermissionsManager found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)
     Duplicate class com.mapbox.android.core.permissions.PermissionsManager$AccuracyAuthorization found in modules jetified-common-23.4.0-runtime (com.mapbox.common:common:23.4.0) and jetified-mapbox-android-core-5.0.0-runtime (com.mapbox.mapboxsdk:mapbox-android-core:5.0.0)

     Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
Exception: Gradle task assembleDebug failed with exit code 1

 

그리고 나서 example 파일을 참고하여 샘플 앱을 실행하면 됩니다.

https://github.com/flutter-mapbox-gl/maps/tree/master/example

 


 

728x90