Mapbox with AR Core + AR Core Extension fails to build
Note: If this is a bug or support ticket, please provide the following information:
- Unity version: 2020.3.31f1
- Scripting Runtime Version: .NET Standard
- Scripting Backend: IL2CPP
- Api Compatibility Level: level 28 -> Highest
- Mapbox SDK version: 2.1.1
- AR Foundation Version: 4.1.9 *AR Core Extensions Version 1.32.0
- The platform you're building to: Android
- A description of what you're trying to do: Add mapbox functionality to ARCore application
- Steps to recreate the bug if appropriate: -Create new project with AR Template 2020.3.31f1 -Follow and implement: https://developers.google.com/ar/develop/unity-arf/geospatial/developer-guide-android -add Geospatial scene to build -Build(will Build sucessfully if followed steps) -Add Mapbox package in(Remove 4 AR folders) -will work in editor -Build and see errors in console
- Links to your logs are also helpful: https://github.com/AgerstnerDev/Logs/raw/main/Editor.log
I am attempting to add Mapbox to my AR Core + AR Core extensions unity application. But upon adding the package I am no longer able to build my app. I have completely trimmed the 4 AR folders as we do not plan to use any of mapbox AR features and just need to location tools and that allows me to run mapbox in my editor but upon building out I am met with the following errors and the log above. It seems maybe there is some duplicate classes being referenced which breaks the unity build but I can't seem to track anything down. I have both SDKs running in their own 2020.3.31f1 projects and they work fine until you add the other in then the builds completely break. Would massively appreciate any insight on this issue.
> Task :unityLibrary:mergeReleaseShaders UP-TO-DATE
> Task :unityLibrary:compileReleaseShaders NO-SOURCE
> Task :unityLibrary:generateReleaseAssets UP-TO-DATE
> Task :launcher:checkReleaseDuplicateClasses FAILED
> Task :unityLibrary:packageReleaseAssets
23 actionable tasks: 3 executed, 20 up-to-date
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\Hub\Editor\2020.3.31f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2020.3.31f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
stderr[
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'
I had a similar issue and figured out that it was because of the android libraries that are included with Mapbox in Mapbox/Core/Plugins/Android. If they already exist in another folder because of other dependencies, then the gradle builder will fail with a very useless error message (and often after a very long time).
If you look further down in your logs, then you'll see
Duplicate class android.support.compat.BuildConfig found in modules com.android.support.support-compat-26.1.0-runtime.jar (:com.android.support.support-compat-26.1.0:) and support-compat-25.1.0-runtime.jar (:support-compat-25.1.0:)
Here the culprit is the support-compat-25 file.
You can now keep removing duplicate files until it will build.
Suggested fix: Mapbox should use the Android dependency resolver: https://github.com/googlesamples/unity-jar-resolver#android-resolver-usage
thanks a lot for the fix @pjarnfelt