Failed to resolve assembly : 'Java.Interop' - xamarin

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.

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.

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.
Unload your Common code project
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>
Delete this segment from csproj.
Load the project
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.
Go there and move the mechanism to an Android specific project.

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

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

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.

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...

You need to check your PLC project on Android link. In PLC project ctrl+f and lets go find "Android" and delete it.

Related

Non-CrossTargeting GetTargetFrameworks target error with VS 2019

I've just updated my VS to ver. 16.8.3 and now suddenly I am getting this error:
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1720,5): error :
Internal MSBuild error: Non-CrossTargeting GetTargetFrameworks target should not be used in cross targeting (outer) build
Not sure at all what to do about this.
We have been working on this project for years and never had such an issue.
Any thoughts?
Seems that the problem is with projects that use multiple .net frameworks AND they referenence ANOTHER project that uses multiple .net frameworks
I have a MINIMAL sample solution at: my public drive
The solution contains two minimal/empty projects that are technically the same except that the one named Microdesk.DbApp referencing the one name Microdesk.Infrastructure.
The Infrastructure project compiles fine while the DbApp project throws the above error.
This solution was working fine for us for multiple years and broke with the latest VS release 16.8.3
Okay, partially my bad.
I did re-compile the EMPTY sample project and found that despite the compiler error, the solution does build.
1>------ Rebuild All started: Project: Microdesk.BIMrxCommon.Infrastructure, Configuration: Debug2020 Any CPU ------
1> Microdesk.BIMrxCommon.Infrastructure -> C:\Work\Microdesk.BIMrx\bin\Debug2020\Microdesk.BIMrxCommon.Infrastructure.dll
2>------ Rebuild All started: Project: Microdesk.BIMrxCommon.DbApp, Configuration: Debug2020 Any CPU ------
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1720,5): error : Internal MSBuild error: Non-CrossTargeting GetTargetFrameworks target should not be used in cross targeting (outer) build
2> Microdesk.BIMrxCommon.DbApp -> C:\Work\Microdesk.BIMrx\bin\Debug2020\Microdesk.BIMrxCommon.DbApp.dll
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
BUT if you try to USE anything from the Infrastructure project in the referencing DbApp project then the Solution will NOT compile
Rebuild started...
1>------ Rebuild All started: Project: Microdesk.BIMrxCommon.Infrastructure, Configuration: Debug2020 Any CPU ------
2>------ Rebuild All started: Project: Microdesk.BIMrxCommon.DbApp, Configuration: Debug2020 Any CPU ------
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1720,5): error : Internal MSBuild error: Non-CrossTargeting GetTargetFrameworks target should not be used in cross targeting (outer) build
2>C:\Work\Microdesk.BIMrx\BIMrxCommon\Microdesk.BIMrxCommon.DbApp\DerivedClass.cs(1,29,1,4
): error CS0234: The type or namespace name 'Infrastructure' does not exist in the namespace 'Microdesk.BIMrxCommon' (are you missing an assembly reference?)
2>C:\Work\Microdesk.BIMrx\BIMrxCommon\Microdesk.BIMrxCommon.DbApp\DerivedClass.cs(5,33,5,42): error CS0246: The type or namespace name 'BaseClass' could not be found (are you missing a using directive or an assembly reference?)
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
I did upload a second sample project named "Microdesk.BIMrx (2).zip" to the previous OneDrive directory
When I test your issue in your side, I did not face the same behaviors as you described. So I guess that there is some issues on your current vs environment due to the update. And maybe the update broke some tools of VS.
So please try the following steps to troubleshoot it:
Suggestions
1) disable any third party installed extensions under Extensions-->Manage Extensions-->Installed
2) close VS, delete .vs hidden folder, every bin and obj folder of your project.
and also delete all cache files under C:\Users\xxx(current user)\AppData\Local\Microsoft\VisualStudio\16.0_xxx\ComponentModelCache
Then, restart VS to test again.
3) or create a new project and then migrate the content from the old into the new one to test whether the issue is related to your VS or the special project itself.
4) If this does not work, do an initialization operation on your VS.
Close VS, delete the whole user folder under C:\Users\xxx(current user)\AppData\Local\Microsoft\VisualStudio\16.0_xxx and then restart VS to test again.
5) repair vs from the vs_installer

Building Xamarin.Forms iOS project from command line with msbuild

I'm trying to build a Xamarin.Forms iOS project via command line for CI/CD purposes directly on macOS:
msbuild C4S_MobileApp.iOS/C4S_MobileApp.iOS.csproj /restore /p:Platform=iPhone /p:ArchiveOnBuild=true /p:Configuration="Release" /p:BuildProjectReferences="false"
The problem is the shared app project which I avoid rebuilding with /p:BuildProjectReferences="false" and whose .dll can't be found:
CSC : error CS0006: Metadata file '/Users/c4s/Projects/c4s_refactored/c4s-refactored-mobile-app/C4S_MobileApp/bin/iPhone/Release/netstandard2.1/C4S.MobileApp.dll' could not be found [/Users/c4s/Projects/c4s_refactored/c4s-refactored-mobile-app/C4S_MobileApp.iOS/C4S_MobileApp.iOS.csproj]
MSBuild assumes the .dll in C4S_MobileApp/bin/iPhone/Release/netstandard2.1/ but it's in C4S_MobileApp/bin/Release/netstandard2.1. An ugly solution would be to copy the C4S.MobileApp.dll to that location. Building without /p:BuildProjectReferences="false" works because msbuild then creates C4S_MobileApp/bin/iPhone/Release/netstandard2.1/C4S.MobileApp.dll
I added the parameter /p:AssemblySearchPaths="C4S_MobileApp/bin/Release/netstandard2.1" to msbuild command and also added <AssemblySearchPaths>C4S_MobileApp/bin/Release/netstandard2.1;$(AssemblySearchPaths)</AssemblySearchPaths> to the C4S_MobileApp.iOS.csproj file under Release|iPhone configuration but it seems to be ignored by msbuild.
Folder structure:
c4s-refactored-mobile-app/
-> C4S_MobileApp/
-> C4S_MobileApp.iOS/
Thanks for your help and suggestions.
Unfortunately it's a bug in Xamarin.iOS: https://github.com/xamarin/xamarin-macios/issues/10308

error MSB6006: "lc.exe" exited with code -1

I can't build my application anymore,
every time I try to compile the following error arises.
error MSB6006: "lc.exe" exited with code -1
I've never changed anything within the Microsoft.Common.CurrentVersion.targets file (or any other file which is related to MSBuild).
Full path to the file:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets
Rows where the error seems to be/arise:
<LC
Sources="#(_LicxFile)"
LicenseTarget="$(TargetFileName)"
OutputDirectory="$(IntermediateOutputPath)"
OutputLicense="$(IntermediateOutputPath)$(TargetFileName).licenses"
ReferencedAssemblies="#(ReferencePathWithRefAssemblies);#(ReferenceDependencyPaths)"
NoLogo="$(NoLogo)"
ToolPath="$(LCToolPath)"
SdkToolsPath="$(TargetFrameworkSDKToolsDirectory)"
EnvironmentVariables="$(LCEnvironment)"
MSBuildArchitecture="$(LCMSBuildArchitecture)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
>
The main problem here is that I can compile every other application, but not my most important one which is written in C# WPF with the .NET Framework 4.7.2.
Does anyone have a clue why I might can't compile the solution?
error MSB6006: “lc.exe” exited with code -1
This error means that your project has something wrong rather than Microsoft.Common.CurrentVersion.targets file
In fact, to see the specific error, you should set your Build Output log to Diagnostic/Detailed by Tools-->Options-->Projects and Solutions-->Build and Run-->set MSBuild project build output verbosity to Diagnostic/Detailed. Then when you build again, you can see the detailed info about it.
And you can try to follow these syggestions:
Please check whether you have any warnings on your nuget packages. If so, please reinstall them or just use update-Package -reinstall under Package Manage Console.
If you have any post(pre)-build event(Right-click on your project-->Properties-->Build Event), please check whether the command has some errors.
If you have licenses.licx files, you should exclude them from your project.
you can try to create a new WPF project and then add the same as the previous project to test if it is the issue of your project.
do a repair in VS Installer in case there are something with your VS Environment or update your VS to the latest version.
In addition, if possible, please share the xxxxx.csproj file of your WPF project with us to troubleshoot your issue quickly. Also, there is a similar issue about this error.

How can I run Xamarin.Forms in my project from it's source, so I can set breakpoints etc in Xamarin.Froms

I want to be able to run Xamarin.Forms from source so I can set breakpoints etc in it. I want to do this primarily so I can see how things get called so I can better understand how it works in response to my use of it in my app. I don't want to do it in the final app, I'd just like to swap out the source version for the nuget package in the end. During development though I would like to see how it runs things to better understand how I can manipulate/override/implement different details.
So far I am close to getting it to compile with my project, but I get 2 build issues realated to Xamarin.Forms.Conrols.Issues I think they are just unit tests, but it stops the build.
/Users/username/github/Xamarin/Xamarin.Forms/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39636.xaml: Error: Object reference not set to an instance of an object (Xamarin.Forms.Controls)
And
/Users/username/github/Xamarin/Xamarin.Forms/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PlatformSpecifics_iOSTranslucentNavBarX.xaml: Error: Object reference not set to an instance of an object (Xamarin.Forms.Controls)
Maybe there is a better way to run it from source and have it integrate with a project and I am just missing it?
These are the projects I have added to my project in a Solution Folder:
Maybe I am on the right path, maybe not. Currently I am only targeting iOS I have an Android project but I am not concerned with that at the moment, just trying to limit it to running on iOS. If that's an issue I can definitely change it. It shouldn't care about the Android parts if I am building for iOS only. Maybe it does?
... LATER ...
Ok tinkering some more I got it down to these packages:
When I right click on the solution folder and select: "Build Xamarin.Forms" the build succeeds. It only fails now with the following error when I try to build my app's Form's project:
/Users/username/github/Xamarin/MyProject/App.xaml.cs(13,13): Error CS0103: The name 'InitializeComponent' does not exist in the current context (CS0103) (MyProject)
I get 51 errors whenever it references anything inside Xamarin.Forms or when it's trying to access a x:Name in some XAML from the code behind.
Intellisense sees the method as well, in this case InitializeComponent so at least that seems to know about it.
Ok, I got it. Here's how I did it:
Clone the Xamarin.Formsrepo from github:
https://github.com/xamarin/Xamarin.Forms
The following applies to Xamarin.Forms 2.3.4.247
cd into the newly cloned repo and checkout that tag corresponding to Xamarin Forms v2.3.4.247:
$ git clone git#github.com:xamarin/Xamarin.Forms.git
$ cd Xamarin.Forms
$ git checkout 2.3.4-2
Add these projects into your project. I placed them in a new solution folder within the project in Visual Studio Mac. I was only concerned with iOS. It would be similar for Android, just adding those specific libs. To figure how the dependencies I just opened the Xamarin.Forms.sln file and check each project's references.
Xamarin.Forms.Platform
Xamarin.Forms.Core
Xamarin.Forms.Platform.iOS
Xamarin.Forms.Xaml
Xamarin.Forms.Build.Tasks
Xamarin.Forms.Xaml.Xamlc
Xamarin.Forms.Xaml.Xamlg
Next, update packages for Xamarin.Forms.Build.Tasks (Mono.Cecil is missing when you import this project. It has a little warning icon by it in the packages list UI)
Now cd to your project folder and copy the .nu* files from the Xamarin.Forms Repo:
$ ls -1
Xamarin.Forms
YourProject
$ cd YourProject
$ cp -r ../Xamarin.Forms/.nu* ./
Afterwards, in the following to csprojfiles (The forms project and the platform project):
YourProject/YourProject/YourProject.csproj
YourProject/iOS/SourceTest.iOS.csproj
file add the following <Import> at the bottom before </Project>:
<Import Project="..\.nuspec\Xamarin.Forms.targets" Condition="Exists('..\.nuspec\Xamarin.Forms.targets')" />
Note this is referencing the files we copied above.
Finally it's time to add the references in Visual Studio to both projects.
Forms Project
Platform Project
That's it. It should compile now and you can add breakpoints into Xamarin.Forms and see how things run. Be sure you added that <Import> node above to ALL csproj files using Xamarin.Forms. From the looks of it, It's responsible for triggering XamlC to process the XAML. When you install Xamarin.Forms from Nuget, it adds this for you. Also be sure you have copied the *.nu files mentioned above to the root of your solution directory.
Remember, once you are done tinkering and you decide to install the Nuget Xamarin.Forms package, you may need to undo some of the changes you made above. For example, check the csproj files to be sure the <Import> is only from the package install.
In case you get compiler errors, check the Xamarin project references. Here are the individual Xamarin related inter-project dependencies that I used to generate the project reference list above.
Xamarin.Forms.Core
References
Xamarin.Forms.Platform
Xamarin.Forms.Platform
References
None
Xamarin.Forms.Platform.iOS
References
Xamarin.Forms.Core
Xamarin.Forms.Xaml
References
Xamarin.Forms.Core
Xamarin.Forms.Xaml.Xamlc
References
Xamarin.Forms.Build.Tasks
Xamarin.Forms.Xaml.Xamlg
References
Xamarin.Forms.Build.Tasks
Xamarin.Forms.Build.Tasks
References
Xamarin.Forms.Core
Xamarin.Forms.Xaml
In addition to AJ Venturella's answer, you also need in 2022:
...
<Import Project="..\..\.nuspec\Xamarin.Forms.targets" />
<Import Project="..\..\.nuspec\Xamarin.Forms.props" />
<Import Project="..\..\.nuspec\Xamarin.Forms.DefaultItems.targets" />
<Import Project="..\..\.nuspec\Xamarin.Forms.DefaultItems.props" />
</Project>
Open .nuspec\Xamarin.Forms.nuspec and check the content that targets "build". It's what's above.

Xamarin.Droid Package creation failed

I chose Build -> Archive for publishing
and I am getting the following error
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2):
Error: Could not load assembly ‘myapp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the
Mono for Android profile? (myapp.Droid)
It was working earlier but now not anymore
I had the exact same scenario, the project used to archive but doesn't any longer, same OS, debug is also perfectly fine.
I found that I only had armeabi-v7a ticked, after ticking x86 it seemed to work.
Step1:
Change Linker Mode
Step2:
Delete obj & bin files in all platforms
Step3:
Rebuild your solution in Debug mode.
Step4:
Now put release mode then try maybe it will work for you
You have to use the Release|AnyCPU when building the project instead of Release|ARM. That worked for me.

Resources