简体   繁体   中英

C# Xamarin Java.Interop error?

Hello since the last Xamarin update we get this error .

CS0012 The type 'IJavaPeerable' is defined in an assembly that is not referenced. You must add a reference to assembly 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. ImageLibrary C:\\Users\\rutge\\Source\\Repos\\GarderobeApp\\ImageSwiper\\ImageSwiper.cs 33 Active

Does anybody have an idea what this means?

You can found it here

C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\MonoAndroid\\v1.0\\Java.Interop.dll

then :

  1. Go to your Android project
  2. Right Click in reference and choose "Add Reference"
  3. Browse file location
  4. Add and done

if you still get error, try to rebuild your project

I go the same error after the last update. You just have to add the reference to Java.Interop to resolve the problem.

  1. Go to your Android project
  2. Right Click in reference and choose "Add Reference"
  3. On Assembly, look for Java.Interop and add it
  4. Rebuild your project

If you need some screenshots, I can provide them later.

In my case it was a bit different, I couldn't find monoandroid folder in

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework. 

So on further I searched and found it in

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid

This might be the case with someone else.

You can hover over the offending line and see the missing DLL.

线路抱怨缺少参考

Now add the missing reference;

  1. Open the Solution Explorer, and within References right click, and select Add Reference从解决方案资源管理器添加引用

  2. Within the Reference Manager click Browse, and Browse again. 添加参考

  3. In the file dialog copy and paste this path:

    C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\MonoAndroid\\v1.0\\

转到DLL路径

Click Java.Interop.dll

添加文件

  1. Okay the Reference Manager

You can directly copy the assembly Java.Interop.dll from the C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\MonoAndroid\\v1.0 to the bin/Debug folder of your project to resolve the issue.

This procedure perfectly worked for me.

Thanks,

These errors are not due to a problem with the solution or the references. They are a by-product of other changes that seem to confuse tools like ReSharper . At least this is correct in my case, my solution still compiles and functions without manually referencing any Reference Assemblies.

There is a Xamarin bug report for this but they determined this to be an external issue with ReSharper as per my experience.

Rather than manually adding references to the project you can also tell ReSharper to simply ignore the errors by opening:

ReSharper -> Windows -> Solution Errors

And then ignoring the issues here.

In my case iOS and Android use the seem Business Layer when I run my android application works ok but when I run iOS show me the error You must add a reference to assembly 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

The problem: I was using JSONObject from Org.Json

https://docs.microsoft.com/en-us/dotnet/api/org.json.jsonobject?view=xamarin-android-sdk-9

this dll just work with android

I need change for JsonObject from System.Json

https://docs.microsoft.com/en-us/dotnet/api/system.json.jsonobject?view=dotnet-plat-ext-2.1

That was my solution, now my two applications work

如果您仍然找不到 Java.Interop,请在 C: 驱动器内的搜索栏中搜索“Java.Interop”并将其添加为对您项目的引用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM