Xamarin.Android using a java binding library with MultiImageChooser

2.9k Views Asked by At

I've tried using a Java Binding Library in order to use MultiImageChooser (https://github.com/derosa/MultiImageChooser).

These are the steps I've taken :

  1. Loaded the MultiImageChooser project in eclipse and exported a gallery.jar.
  2. Created a Java Binding Library project in my solution, in Visual Studio.
  3. Added gallery.jar to "Jars" and changed its type to "EmbeddedJar".
  4. Added the reference jars (universal-image-loader-1.8.0.jar and android-support-v4.jar) and changed their type to "EmbeddedReferenceJar".
  5. Added to Metadata.xml a transform in order to pass compilation (covariant return type) :

    attr
    path="/api/package[@name='com.luminous.pick']/class[@name='GalleryAdapter']/method[@name='getItem']" name="managedReturn"> Java.Lang.Object
    /attr

  6. It passes compliation, but the BuildApk task fails with System.ArgumentException : An item with the same key has already been added.

(_BuildApkFastDev target) -> C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: The "BuildApk" task failed unexpectedly. [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: System.ArgumentException: An item with the same key has already been added. [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at Ionic.Zip.ZipFile.InternalAddEntry(ZipEntry ze) [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at Ionic.Zip.ZipFile.AddEntry(String entryName, Stream stream) [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at Ionic.Zip.ZipFile.AddEntry(String entryName, Byte[] byteContent) [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at Xamarin.Android.Tasks.BuildApk.Execute() [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj] C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1132,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d_20.MoveNext() [C:\awork\TestClientNG\TestAndroidApp\TestAndroidApp.csproj]

Any idea how to debug or continue with this?

1

There are 1 best solutions below

1
On BEST ANSWER

Good thing you listed the exact steps you performed, I was stuck with the same issue and was breaking my head all night. The problem has to do with the jar you built in eclipse. When exporting to jar make sure to uncheck all the additional project files like .classpath, .project, pom.xml, project.properties and particularly AndroidManifest.xml. Since these made their way into the jar, there ended up being two android manifest files resulting in the error you are seeing.