Getting java.exe exited with code 2 while building the app - xamarin.android

I upgraded my android sdk api version from 27 to 28 and started getting the "java.exe" exited with code 2 while compiling a build.
Output:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2667,3): warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="SQLitePCLRaw.batteries_v2" culture="neutral" publicKeyToken="8226ea5df37bcae9" /><bindingRedirect oldVersion="0.0.0.0-1.1.13.388" newVersion="1.1.13.388" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="SQLitePCLRaw.core" culture="neutral" publicKeyToken="1488e028ca7ab535" /><bindingRedirect oldVersion="0.0.0.0-1.1.13.388" newVersion="1.1.13.388" /></dependentAssembly></assemblyBinding>
1>CREATEMULTIDEXMAINDEXCLASSLIST : warning : can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [__reference__commons-io-2.4.jar:META-INF/LICENSE.txt])
1>CREATEMULTIDEXMAINDEXCLASSLIST : warning : can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [__reference__commons-io-2.4.jar:META-INF/NOTICE.txt])
1>CREATEMULTIDEXMAINDEXCLASSLIST : warning : can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [__reference__commons-lang-2.6.jar:META-INF/LICENSE.txt])
1>CREATEMULTIDEXMAINDEXCLASSLIST : warning : can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [__reference__commons-lang-2.6.jar:META-INF/NOTICE.txt])
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2610,3): error MSB6006: "java.exe" exited with code 2.
I am not able to find out the root cause.
Edit
I have multidex enabled in my app but still I am having the same issue.

So I had this and in my case it simply meant the password I was supplying for the Java keystore with the signing cert in was wrong! I do think they could give a more descriptive error message in that case, but apparently not.
I should add that this was from a CI process doing a scripted build using the CLI version of msbuild, but doubt that makes a difference.

I found the answer to my question. The answer isnt that great but it works. I was using visual studio 2017 and it had some problem with android 9. I updated it to visual studio 2019 and the app started building properly.

Related

VS 2019 with Xamarin, cant debug due to warning: Debugging symbol file is not valid and was ignored

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(373,3): warning MT0178: Debugging symbol file for '/Users/appledevelopment/Library/Caches/Xamarin/mtbs/builds/XamAppHartzSystems.iOS/831856682f36592c89c1d1be72305370c507305528b30a6064078e5ddad8b0d1/bin/iPhoneSimulator/Debug/XamAppHartzSystems.dll' is not valid and was ignored.
Getting this warning in my build process. The build completes without errors.
The build is for a Xamarin iOS project that was working before I updated xcode and visual studio 19 to latest versions.
When I try to put a brakepoint in my shared library, it will not stop in the debugger due to the above warning.
I have tried to clear all the obj and bin folders, but that does not help.
I can't seem to find why it thinks the symbol file is invalid.
Windows VS is up to date
Mac xcode is up to date
Mac VS is up to date
Using Xamarin Forms 4.8.1821, tried the latest version too with no luck.
How do I find out why my symbol file is invalid...
Answer: Somehow in the Library Build Settings, the Debugging information was set to Pdb-only. I changed it to Portable and it fixed the problem.
It happened to a few of my projects after upgrading to the latest VS and xcode.

VS 2019 update to 16.8.4 broke every single one of my solutions

I don't recall the previous version I had (it could have been 16.8.1), but updating just now to 16.8.4 results in none of my solution projects being able to load. Here's the output window for one of my solutions:
F:\Users\username\Documents\Visual Studio Projects\FitnessManagerCore\FitnessManagerCore\FitnessManagerCore.csproj : error : The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" is correct, and that the file exists on disk. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets
F:\Users\username\Documents\Visual Studio Projects\GeneralUtilities\GeneralUtilities\GeneralUtilities.csproj : error : The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" is correct, and that the file exists on disk. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets
F:\Users\username\Documents\Visual Studio Projects\FitnessManagerCore\FitnessManagerConsole\FitnessManagerConsole.csproj : error : The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" is correct, and that the file exists on disk. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets
VS advised to try to reload the projects manually. When I attempt this, I get the following error message:
It seems Microsoft has no means to roll back a previous installation. I do not have a restore point. I do not want to uninstall/reinstall.
Edit:
I just tried creating a new solution to see what would happen if I tried to load one of my existing projects. When creating a console app w/ .NET Core, I get this:
Update:
This latest VS 2019 simply does not want to work on my machine in any capacity. I uninstalled VS 2019, rebooted, and attempted to reinstall. The installation stops midway with the below error message. When I click "Report this problem", it opens a Microsoft web page to report the issue, but says "Disconnected from Visual Studio". Since I can't roll back to a previous version according to what I'm reading, I guess I just can't use VS 2019 anymore.
You could check in your csporj file if you have:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
You would need to change MSBuildToolsPath to MSBuildBinPath, like this:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
When you create a project in Visual Studio 2008, $(MSBuildToolsPath) is added by default to your csproj file as the path to Microsoft.Build.Engine v3.5.
Be sure to change it to $(MSBuildBinPath) which is the path to Microsoft.Build.Engine v2.0.
(more info here)

How to solve rzc generate exited code 1 error

When i pulled code from team explorer in visual studio code . Rzc generate exited code 1 error occured. I am unable to build project.how to solve this error?
Target framework .net core 3.1
Open the Project in visual studio-> check in views folder for any files having X - red color symbol then remove that file from visual studio.
Previously you deleted the files from folder - that is the issue.
ie, Razor Engine trying to render those files, but the engine could not find the physical location of that file, that is the problem. Always delete the unwanted files using the visual studio or any project editor. That is the best practice.
I solved rzc generate exited with code 1 microsoft.net.sdk.razor.codegeneration.targets
by undoing the changes that deleted a project from the folder in file explorer instead of visual studio.
In your Project.csproj, you should have a piece of XML code like this:
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Views\Home\" />
<Folder Include="Views\Shared\" />
</ItemGroup>
It depends on your folder structure.
In case you are using Windows 7 and getting the 'rzc generate exited with code -2147450750' while debugging a .NET Core app, try installing the standalone package: Microsoft Update Catalog - KB4457144.
I had the exact same error message (apart from the directories) on Windows 7 with a newer VC++ distribution already present.
The package contains the KB2533623 that we want. Details of KB4457144: September 11, 2018—KB4457144 (Monthly Rollup)
After installation and a reboot, dotnet new console goes through without an error.
Dell forum source: Microsoft Windows 7 Update KB2533623 needed to install Dell Update Package (DUP)
You are using visual studio 2019 older version then you have updated to the latest version has fixed my issue.
Yes. I have delete some files manually from folder.
So i resolved that issue by deleting the unloaded files from that deleted folder as
red cross files will be still in our visual studio if we delete
them outside.

Visual Studio Team Services build is unable to find a library

​I am trying to use Team Services CI Build, but it keeps on failing with the same error:
##[error]MobileClient\LoginNavigation\CommentPage.xaml.cs(1,7): Error CS0246: The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)
Which seems to be right, since in a previous step it is complaining about not finding that library:
##[warning]C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Mono.Android". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Also, it is logged where the build is searching it:
For SearchPath "{HintPathFromItem}".
Considered "..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\Mono.Android.dll", but it d idn't exist.For SearchPath "{TargetFrameworkDirectory}".
For SearchPath "{TargetFrameworkDirectory}".
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259\Mono.Android.winmd", but it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259\Mono.Android.dll", but it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259\Mono.Android.exe", but it didn't exist.
For SearchPath "{RawFileName}".
Considered treating "Mono.Android" as a file name, but it didn't exist.
To my understanding, this file is missing in the Team Services build server, right? How could I solve this? Should it be necessary to change this directory?
One important thing is that locally, in my machine, the Visual Studio and the command line MSBuild are working correctly.
This happens during the Visual Studio Build step, which has the following configuration:
MSBuild Configuration: MSBuild ​x86
Visual Studio Version: Visual Studio 2015
MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\"
Visual Studio Build Solution step version: 1.*
Here are the steps of the Team Services build:
​
​​
Ok so after reading the answers and suggestions I received, I got a hint of what I had to do to resolve this. Basically, I was making two mistakes:
First of all, on the project that was failing, I changed the Mono.Android reference to one inside the project's folder. Even though that error disappeared, I kept on having more and more errors related to Xamarin and Android.
So that's when I followed another suggestion in this thread: using a Xamarin.Android template. The thing is, that in this project I have a .sln file, which contains different type of projects, including a Xamarin project, a Web Api, and some Class Libraries. I was trying to build them all in the same Team Services build definition, but I realized it was much more efficient to have different definitions according to the different type of projects.
In consequence, I ended up having a build definition for the Xamarin project, using the Xamarin.Android template, and another one for a .sln file I created with all the projects used by the Web Api project. The amount of errors was reduced drastically, and I felt I wasn't "swimming against the tide" anymore.
I would suggest everyone having a solution with a wide variety of project types to do the same.

Can't publish to IIS - Copying file failed

Error 5 Copying file Uploads\People\bzbu0pdh.png to obj\Release\Package\PackageTmp\Uploads\People\bzbu0pdh.png failed. Could not find file 'Uploads\People\bzbu0pdh.png'. 0 0 SampleProject.Web
I get this error when I try to publish my project from Visual Studio 2013. I'm pretty sure this is an unwanted file.
I tried creating a file with the same name and putting it in Uploads\People and included that in project. It didn't help either.
Browse to that directory in Visual Studio and you'll see that VS believes there to be a file there. you can right click and exclude it from the project and VS will update the project file for you.

Resources