Bug 20030 - Dex compilation failure with unexpected "already added" error
Summary: Dex compilation failure with unexpected "already added" error
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-05-25 12:59 UTC by BurnSpamAddress
Modified: 2014-05-26 06:28 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 20030 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description BurnSpamAddress 2014-05-25 12:59:50 UTC
This issue affects the integration of https://github.com/mono/opentk with https://github.com/opentk/opentk.

Steps to reproduce:
1. Create a new Android application using the "Android Application" template.
2. Append the following code to MainActivity.cs:
namespace OpenTK
{
    public class GameViewBase : SurfaceView
    {
        public GameViewBase(Context context) : base(context)
        {
        }
    }
}
3. Compile.

Compilation will fail with:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: error : Tool exited with code: 1. Output: 
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lopentk/GameViewBase;

Note that OpenTK.dll is NOT referenced in the project references. Complete build log below:


Building: AndroidProblem (Debug)

Build started 25/5/2014 6:51:06 μ.μ..
__________________________________________________
Project "/tmp/AndroidProblem/AndroidProblem/AndroidProblem.csproj" (Build target(s)):
	
	Target _CheckProjectItems:
		CheckProjectItems Task
		  NativeLibraries:
		  JavaLibraries:
		  JavaSourceFiles:
	
	Target _ComputeAndroidAssetsPaths:
		  ResourceFiles:
		  IntermediateFiles:
	
	Target _GenerateAndroidAssetsDir:
	No output files were specified for target _GenerateAndroidAssetsDir, skipping.
	
	Target _ComputeAndroidResourcePaths:
		  ResourceFiles:
		    Resources/layout/Main.axml
		    Resources/values/Strings.xml
		    Resources/drawable/Icon.png
		  IntermediateFiles:
	
	Target _GenerateAndroidResourceDir:
	Skipping target "_GenerateAndroidResourceDir" because its outputs are up-to-date.
	
	Target _ResolveMonoAndroidSdks:
		MonoAndroid Tools: /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/
		MonoAndroid Binaries: /Library/Frameworks/Xamarin.Android.framework/Versions/Current/bin/
		Android Platform API level: 14
		TargetFrameworkVersion: v4.0
		Android NDK: /Users/someone/Library/Developer/Xamarin/android-ndk/android-ndk-r8d/
		Android SDK: /Users/someone/Library/Developer/Xamarin/android-sdk-mac_x86/
		Android SDK Build Tools: /Users/someone/Library/Developer/Xamarin/android-sdk-mac_x86/build-tools/19.0.3/
		Java SDK: /usr/
	
	Target _ValidateAndroidPackageProperties:
		GetAndroidPackageName Task
		  ManifestFile: /tmp/AndroidProblem/AndroidProblem/Properties/AndroidManifest.xml
		  AssemblyName: AndroidProblem
		  PackageName: AndroidProblem.AndroidProblem
	
	Target _BuildDependencies:
		Resolved library outputs: 
	
	Target _ExtractLibraryProjectImports:
		  Assemblies: 
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		  Jars: 
		  ResolvedResourceDirectories: 
		  ResolvedAssetDirectories: 
		  ResolvedEnvironmentFiles: 
	
	Target _GetLibraryImports:
		  NativeLibraries: 
		  Jars: 
	
	Target _CheckDuplicateJavaLibraries:
		  JavaSourceFiles:
		  JavaLibraries:
	
	Target _GetAdditionalResourcesFromAssemblies:
		  Assemblies: 
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
	
	Target _UpdateAndroidResgen:
	Skipping target "_UpdateAndroidResgen" because its outputs are up-to-date.
	
	Target PrepareForBuild:
		Configuration: Debug Platform: AnyCPU
	
	Target GenerateSatelliteAssemblies:
	No input files were specified for target GenerateSatelliteAssemblies, skipping.
	
	Target GenerateTargetFrameworkMonikerAttribute:
	Skipping target "GenerateTargetFrameworkMonikerAttribute" because its outputs are up-to-date.
	
	Target CoreCompile:
	Skipping target "CoreCompile" because its outputs are up-to-date.
	
	Target _ResolveAssemblies:
		ResolveAssemblies Task
		  ReferenceAssembliesDirectory: /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0;/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0;/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Facades/
		  I18nAssemblies: 
		  LinkMode: None
		  Assemblies:
		    bin/Debug/AndroidProblem.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		  Assembly /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll is ignored: system assembly is used instead.
		  Assembly /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll is ignored: system assembly is used instead.
		  Assembly /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll is ignored: system assembly is used instead.
		  Assembly /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll is ignored: system assembly is used instead.
		  [Output] ResolvedAssemblies:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Mono.Security.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		  [Output] ResolvedUserAssemblies:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
		  [Output] ResolvedFrameworkAssemblies:
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Mono.Security.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		  [Output] ResolvedDoNotPackageAttributes:
	
	Target _CopyIntermediateAssemblies:
		SourceFiles:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Mono.Security.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		DestinationFiles:
		    obj/Debug/assemblies/AndroidProblem.dll
		    obj/Debug/assemblies/Mono.Android.dll
		    obj/Debug/assemblies/mscorlib.dll
		    obj/Debug/assemblies/System.Xml.dll
		    obj/Debug/assemblies/System.dll
		    obj/Debug/assemblies/Mono.Security.dll
		    obj/Debug/assemblies/System.Core.dll
		SourceFiles:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Mono.Security.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		DestinationFiles:
		    obj/Debug/assemblies/AndroidProblem.dll
		    obj/Debug/assemblies/Mono.Android.dll
		    obj/Debug/assemblies/mscorlib.dll
		    obj/Debug/assemblies/System.Xml.dll
		    obj/Debug/assemblies/System.dll
		    obj/Debug/assemblies/Mono.Security.dll
		    obj/Debug/assemblies/System.Core.dll
	
	Target _ScanAssemblies:
		LinkAssemblies Task
		  UseSharedRuntime: true
		  MainAssembly: obj/Debug/assemblies/AndroidProblem.dll
		  OutputDirectory: obj/Debug/android/assets/
		  I18nAssemblies: 
		  ReferenceAssembliesDirectory: /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0;/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0;/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Facades/
		  ResolvedAssemblies:
		    obj/Debug/assemblies/AndroidProblem.dll
		    obj/Debug/assemblies/Mono.Android.dll
		    obj/Debug/assemblies/mscorlib.dll
		    obj/Debug/assemblies/System.Xml.dll
		    obj/Debug/assemblies/System.dll
		    obj/Debug/assemblies/Mono.Security.dll
		    obj/Debug/assemblies/System.Core.dll
	
	Target _StripEmbeddedLibraries:
		  Assemblies: 
		    obj/Debug/assemblies/AndroidProblem.dll
		    obj/Debug/assemblies/Mono.Android.dll
		    obj/Debug/assemblies/mscorlib.dll
		    obj/Debug/assemblies/System.Xml.dll
		    obj/Debug/assemblies/System.dll
		    obj/Debug/assemblies/Mono.Security.dll
		    obj/Debug/assemblies/System.Core.dll
	
	Target _GenerateJavaStubs:
		  ResolvedAssemblies:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Mono.Security.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		  ResolvedUserAssemblies:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
	
	Target _AddStaticResources:
		Resource obj/Debug/android/assets/machine.config is unchanged. Skipping.
		Resource obj/Debug/android/src/mono/MonoRuntimeProvider.java is unchanged. Skipping.
		Resource obj/Debug/android/src/mono/android/Seppuku.java is unchanged. Skipping.
	
	Target _GeneratePackageManagerJava:
		  ResolvedAssemblies:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/Mono.Android.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Mono.Security.dll
		    /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/System.Core.dll
		  ResolvedUserAssemblies:
		    /tmp/AndroidProblem/AndroidProblem/bin/Debug/AndroidProblem.dll
	
	Target _CreateBaseApk:
	Skipping target "_CreateBaseApk" because its outputs are up-to-date.
	
	Target _CompileJava:
		  JavaSourceFiles:
		  JavaLibraries:
		  ExternalJavaLibraries:
		  AddOnPlatformLibraries:
		Tool /usr//bin/javac execution started with arguments: -J-Dfile.encoding=UTF8 -d obj/Debug/android/bin/classes -classpath /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/mono.android.jar -bootclasspath /Users/someone/Library/Developer/Xamarin/android-sdk-mac_x86/platforms/android-14/android.jar -encoding UTF-8 @/var/folders/35/m7rknr9s01zb2k77pbc2nrz80000gn/T/tmp5886b8ea.tmp 
		Note: Some input files use unchecked or unsafe operations.
		Note: Recompile with -Xlint:unchecked for details.
	
	Target _CompileDex:
		  JavaSourceFiles:
		  JavaLibraries:
		  ExternalJavaLibraries:
		  AdditionalJavaLibraryReferences:
		  DoNotPackageJavaLibraries:
		Tool /usr//bin/java execution started with arguments: -jar /Users/someone/Library/Developer/Xamarin/android-sdk-mac_x86/build-tools/19.0.3//lib/dx.jar --no-strict --dex --output=obj/Debug/android/bin/classes.dex obj/Debug/android/bin/classes /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.0/mono.android.jar 
		
		UNEXPECTED TOP-LEVEL EXCEPTION:
		java.lang.IllegalArgumentException: already added: Lopentk/GameViewBase;
			at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
			at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
			at com.android.dx.command.dexer.Main.processClass(Main.java:685)
			at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
			at com.android.dx.command.dexer.Main.access$600(Main.java:78)
			at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
			at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
			at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
			at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
			at com.android.dx.command.dexer.Main.processOne(Main.java:596)
			at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
			at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
			at com.android.dx.command.dexer.Main.run(Main.java:230)
			at com.android.dx.command.dexer.Main.main(Main.java:199)
			at com.android.dx.command.Main.main(Main.java:103)
		1 error; aborting
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: error : Tool exited with code: 1. Output: 
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lopentk/GameViewBase;
	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
	at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
	at com.android.dx.command.dexer.Main.processClass(Main.java:685)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
	at com.android.dx.command.dexer.Main.access$600(Main.java:78)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
	at com.android.dx.command.dexer.Main.processOne(Main.java:596)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
	at com.android.dx.command.dexer.Main.run(Main.java:230)
	at com.android.dx.command.dexer.Main.main(Main.java:199)
	at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting

	Task "CompileToDalvik" execution -- FAILED
	Done building target "_CompileDex" in project "/tmp/AndroidProblem/AndroidProblem/AndroidProblem.csproj".-- FAILED
	
Done building project "/tmp/AndroidProblem/AndroidProblem/AndroidProblem.csproj".-- FAILED

Build FAILED.
Errors:

---------------------- Done ----------------------

Build: 1 error, 0 warnings
Comment 1 BurnSpamAddress 2014-05-25 16:15:56 UTC
It appears that mono.android.jar contains opentk/GameViewBase.class and opentk_1_0/GameViewBase.class. This means I can use [Register("opentk_1_1/GameViewBase")] to avoid the conflict.

Is there a reason why the opentk .class files are contained in mono.android.jar? They appear to be included even when an application is not using OpenTK.
Comment 2 Prashant manu 2014-05-26 06:28:17 UTC
We have checked as per steps mentioned in description and getting same error.
Screencast:  http://www.screencast.com/t/8w5JyBH0Hwsh

Supplement Info:
Build Output: https://gist.github.com/saurabh360/2896b8f131b00c3ea463
IDE Log: https://gist.github.com/saurabh360/60442baa00c4f53df641

Environment Info:
XS 4.2.5.0
Xam.Android 4.12.3.3