Program type already present error when gradle build

Hi,

When i try to create an android build with gradle. I get this error. I already try to delete and reinstall all sdk’s(currently only 3 services i am using, facebook sdk, google ads and unity iap) But only error information changed(now it says “Program type already present: com.facebook.unity.Constants”, before it said something like " “Program type already present: android.support…”) I already google that problem. But most of the solutions with android studio etc and others doesnt work. I dont have any android studio experience, so is there any practical solution for that issue?

It would be great to share screenshot of Assets/Plugins/Android folder to look into the issue.

this is my android folder, i can’t see any duplication but may be i am missing something

4676684--440381--pluginfold.PNG

Can you please share the error completely?
Also all the libs are listed in the above screenshot or something pending?

CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath “C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx4096m” “bundleRelease”

stderr[
D8: Program type already present: com.facebook.unity.Constants

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformDexArchiveWithExternalLibsDexMergerForRelease’.

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\0.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\1.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\2.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\3.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\6.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\7.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\8.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\9.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\10.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\11.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\12.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\13.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\14.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\15.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\16.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\17.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\18.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\19.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\20.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\21.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\22.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\23.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\24.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\25.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\26.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\27.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\28.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\29.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\30.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\31.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\32.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\33.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\35.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\36.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\37.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\38.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\39.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\40.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\41.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\42.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\43.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\44.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\45.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\46.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\47.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\48.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\49.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\50.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\51.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\52.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\53.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\54.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\55.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\56.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\57.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\58.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\59.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\60.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\61.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\62.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\63.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\64.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\65.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\66.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\67.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\68.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\69.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\70.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\71.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\72.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\73.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\74.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\75.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\76.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\77.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\78.jar, C:\Users\mypc\Documents\mygame\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\79.jar
Learn how to resolve the issue at Menambahkan dependensi build  |  Android Studio  |  Android Developers.
Program type already present: com.facebook.unity.Constants

  • 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

BU?LD FAILED in 48s
]
stdout[
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\28.0.3\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-28\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.1.0f2\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
:checkReleaseClasspath UP-TO-DATE
:preBuild UP-TO-DATE
:GoogleMobileAdsPlugin:preBuild UP-TO-DATE
:GoogleMobileAdsPlugin:preReleaseBuild UP-TO-DATE
:GoogleMobileAdsPlugin:checkReleaseManifest
:GoogleMobileAdsPlugin:processReleaseManifest
:preReleaseBuild UP-TO-DATE
:GoogleMobileAdsPlugin:packageReleaseRenderscript NO-SOURCE
:compileReleaseRenderscript UP-TO-DATE
:generateReleaseResValues UP-TO-DATE
:generateReleaseResources UP-TO-DATE
:GoogleMobileAdsPlugin:compileReleaseRenderscript
:GoogleMobileAdsPlugin:generateReleaseResValues
:GoogleMobileAdsPlugin:generateReleaseResources
:GoogleMobileAdsPlugin:packageReleaseResources
:mergeReleaseResources UP-TO-DATE
:checkReleaseManifest UP-TO-DATE
:createReleaseCompatibleScreenManifests UP-TO-DATE
:mainApkListPersistenceRelease UP-TO-DATE
:processReleaseManifest
:bundleReleaseResources
warn: removing resource com.narcade.mygame1:string/com_facebook_loginview_logged_in_using_facebook_f1gender without required default value.

:mergeReleaseShaders UP-TO-DATE
:compileReleaseShaders UP-TO-DATE
:generateReleaseAssets UP-TO-DATE
:GoogleMobileAdsPlugin:mergeReleaseShaders
:GoogleMobileAdsPlugin:compileReleaseShaders
:GoogleMobileAdsPlugin:generateReleaseAssets
:GoogleMobileAdsPlugin:packageReleaseAssets
:mergeReleaseAssets
:GoogleMobileAdsPlugin:compileReleaseAidl NO-SOURCE
:compileReleaseAidl NO-SOURCE
:generateReleaseBuildConfig UP-TO-DATE
:prepareLintJar UP-TO-DATE
:splitsDiscoveryTaskRelease UP-TO-DATE
:GoogleMobileAdsPlugin:generateReleaseRFile
:processReleaseResources
warn: removing resource com.narcade.mygame1:string/com_facebook_loginview_logged_in_using_facebook_f1gender without required default value.

:generateReleaseSources
:GoogleMobileAdsPlugin:generateReleaseBuildConfig
:GoogleMobileAdsPlugin:prepareLintJar UP-TO-DATE
:GoogleMobileAdsPlugin:generateReleaseSources
:GoogleMobileAdsPlugin:javaPreCompileRelease
:GoogleMobileAdsPlugin:compileReleaseJavaWithJavac
:GoogleMobileAdsPlugin:processReleaseJavaRes NO-SOURCE
:GoogleMobileAdsPlugin:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease
:javaPreCompileRelease UP-TO-DATE
:compileReleaseJavaWithJavac UP-TO-DATE
:transformClassesWithDexBuilderForRelease UP-TO-DATE
:transformDexArchiveWithExternalLibsDexMergerForRelease FAILED
35 actionable tasks: 18 executed, 17 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action1[T] progress, System.String error) (at <177bc8179be6497489c4b5b319f290d7>:0) UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action1[T] progress) (at <177bc8179be6497489c4b5b319f290d7>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <177bc8179be6497489c4b5b319f290d7>:0)
Rethrow as BuildFailedException: Exception of type ‘UnityEditor.Build.BuildFailedException’ was thrown.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <177bc8179be6497489c4b5b319f290d7>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:281)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

all libs are listed at this screenshot, in the plugin/android folder.

do you have any suggestion about the issue? all of the libs are in ss.

finally i found a solution. If anyone will facing this problem, solution is aar files. check plugins/android for duplicated aar files. and check other potential sdk roots like facebook/plugin/android. There will be other aar files.

1 Like

Hello I have this problem too now. There are multiple aar files all over the place with different names. Is deleting all of them the solution? which should i delete?

First search for all *.aar and *.jar files in the project and paste here.

This is actually an Android related problem.

When two libraries (e.g AAR files) contain one or more classes with same packageName (e.g com.example.library.Class1), the Gradle can not decide which one to use and include in the main source path, so it’ll throw an exception.

To solve this you must know which one of these libraries are having duplicate classes (In this case the class is com.facebook.unity.Constants).

Following bullets may be helpful:

  • If you have used mainTemplate.gradle and the JarResolver, this might be the reason to the problem. They may add one library in their own way and the AAR file gets added twice.
  • If you have added only AAR files to the project, you can search their classes.jar and look for the duplicate class (Again, in this case com.facebook.unity.Constants), and find the blamed AAR files and deal with them.

TL; DR

The AAR files are having some classes that are identical. You must find those AAR files and deal with them (Delete one, …).

HI. Where should I look for AAR files?. For me error is this:
D8: Program type already present: com.bazaar.BazaarIABPlugin$2
I Could build an APK before importing a plugin but now I’m getting this error and is referring to the one of the plugin library.
Please tell me if you need more details