7
votes

When I try to build the application I get an exception the following exception :

C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(681,3): error : Failed to resolve assembly: 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

I tried cleaning the project and building it again, also updated the Xamarin.Forms packages but still with no luck.

A little overview on the stack trace :

2>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(681,3): error : Failed to resolve assembly: 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' 2> Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution finished. (TaskId:153) 2> MTouch: 2016-07-05T14:27:15.8191415+05:30 - Finished (TaskId:153) 2> Output Item(s): _NativeLibrary= (TaskId:153) 2>Done executing task "MTouch" -- FAILED. (TaskId:153)

Has anyone received this error? I am running the latest Xamarin for Visual Studio.

6
Did you try to add Java.Interop.dll reference? - jzeferino
@jzeferino Why would I need that. It was working before. I didn't have any reference to Java.Interop. It suddenly stopped working. - Akash Amin
Im just suggesting it to check if it works. Did you had any external library? - jzeferino
@jzeferino Where do I find the Java.Interop.dll? - Akash Amin
Got it. Thank You @SushiHangover. I don't know how but Mono.Android got referenced in my PCL and because of that it was throwing the error in iOS. I removed the reference and it's working now. - Akash Amin

6 Answers

12
votes

As mentioned in the comments above by @SushiHangover Java.Interop.dll is from Xamarin.Android and I was getting an error in Xamarin.IOS.

I had a reference of Mono.Android in PCL which is always referenced in Xamarin.IOS so indirectly I was referencing dll of Xamarin.Android to Xamarin.IOS. Removing the reference from PCL solved my problem.

1
votes

As mentioned by @AkashAmin 'Mono.Android' referenced should not be there in PCL project.

But with this, also make sure that you have not added any 'Android' specific code in PCL project by adding 'using Android', if this was done then you need to remove this code by using 'Dependency Services', Click here

1
votes

I had the same problem and when I removed the android.mono reference from pcl project it worked fine.

I think it happens because we are building project in ios and it doesn't have any android libraries

0
votes

Just in case, I got this error from working with ReSharper on VS2013 (https://bugzilla.xamarin.com/show_bug.cgi?id=41627).

What I did was use the Workaround to explicitly add java.interop.dll assembly to my project. This problem doesn't affect Build so you can deploy first and VS will download java.interop to your app's obj\Debug\linksrc folder, which you can reference...

0
votes

Platform specific code within the Shared Project will cause iOS compiler to attempt to use the platform specific assemblies when compiling.

In my case, I had a reference within my Shared Project's code, within the "using" statements, which was causing iOS to attempt to link to Android specific assemblies.

Removing the code from the Shared Project allowed for successful compiling of the project.

0
votes

Step-by-step instructions on how to fish this one out, as it took me some time to find where the 'Android polluted' peace of code was.

  1. Unload your Common code project

enter image description here

  1. Open .csproj look for something like this

      <ItemGroup>
      <Reference Include="Mono.Android">
       <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v11.0\Mono.Android.dll</HintPath>
     </Reference>
    
  2. Delete this segment from csproj.

  3. Load the project

enter image description here

  1. Clean and rebuild the solution having iOS as startup Project, at this point, you will get a build error that will show which .cs file fails to build due to missing reference.
  2. Go there and move the mechanism to an Android specific project.