Unable to run Xamarin Forms project in Visual Studio 2017 Android emulator - visual-studio

Getting this error when trying to run one of the Xamarin.Forms navigation samples from GitHub (MasterDetailsPage)
Severity Code Description Project File Line Suppression State Error
java.lang.OutOfMemoryError. Consider increasing the value of
$(JavaMaximumHeapSize). Java ran out of memory while executing
'java.exe -jar "C:\Program Files
(x86)\Android\android-sdk\build-tools\23.0.3\lib\dx.jar" --dex
--no-strict --output obj\Debug\android\bin \MasterDetailPage\Droid\obj\Debug\android\bin\classes\classes.zip
"C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.0\mono.android.jar"
obj\Debug\lp\0\jl\formsviewgroup.jar
obj\Debug\lp\10\jl\bin\classes.jar obj\Debug\lp\11\jl\bin\classes.jar
obj\Debug\lp\12\jl\bin\classes.jar obj\Debug\lp\13\jl\bin\classes.jar
obj\Debug\lp\14\jl\bin\classes.jar obj\Debug\lp\15\jl\bin\classes.jar
obj\Debug\lp\16\jl\bin\classes.jar obj\Debug\lp\17\jl\bin\classes.jar
obj\Debug\lp\18\jl\bin\classes.jar obj\Debug\lp\19\jl\bin\classes.jar
obj\Debug\lp\20\jl\bin\classes.jar obj\Debug\lp\21\jl\bin\classes.jar
obj\Debug\lp\3\jl\arch-core-common.jar
obj\Debug\lp\4\jl\arch-lifecycle-common.jar
obj\Debug\lp\5\jl\bin\classes.jar obj\Debug\lp\6\jl\bin\classes.jar
obj\Debug\lp\8\jl\bin\classes.jar obj\Debug\lp\9\jl\bin\classes.jar
C:\Users\me\AppData\Local\Xamarin\Xamarin.GooglePlayServices.Basement\8.4.0\embedded\classes.jar'
MasterDetailPageNavigation.Droid
I tried setting android:largeHeap to true in the AndroidManifest.xml
But the error didn't go away
I also tried to set the Java Max Heap Size to 1G in the Android Advanced Options under the project properties - the project builds without errors but that's about it, the emulator doesn't launch (or if I have it open nothing happens within it - the app doesn't start)
I read somewhere , that if the emulator doesn't start it means there isn't enough memory for it so it fails silently. I forget exactly the details.
But I have plenty of free RAM on my machine 12GB in total and between 6 - 8 GB avail, when visual studio is running.

The problem occurs while building the app not when running. Open the properties of the Android project and there Android options->Advanced you will find Java Max Heap Size. Using a value of 1G (for one gigabyte) should fix the memory problem.

Related

Nativescript - cannot run android on device

I used to be able to run on android and all of a sudden I am getting this error (see below).
The only thing I recall changing is downgrading "nativescript-ui-listview" to "^7.1.0" and "nativescript-ui-sidedrawer" to "~7.0.0" because it otherwise breaks on ios 12.
Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Installing on device f180a829...
More than one .apk found in /Users/manuelmaestrini/Programming/spiio-development/spiiomobile/platforms/android/app/build/outputs/apk directory. Using the last one produced from build.
Successfully installed on device with identifier 'f180a829'.
Application com.spiio.mobile is not running on device f180a829.
This issue may be caused by:
* crash at startup (try `tns debug android --debug-brk` to check why it crashes)
* different application identifier in your package.json and in your gradle files (check your identifier in `package.json` and in all *.gradle files in your App_Resources directory)
* device is locked
* manual closing of the application
Unable to apply changes on device: f180a829. Error is: Application com.spiio.mobile is not running.
Any idea what might be? I tried to do --clean, remove node_modules, hooks, platforms, uninstall and reinstall webpack etc but no luck...

Error "Ensure kernel-qemu is in the same location as your system image"

Yesterday I decided to try out VS2019 for Xamarin projects, so I created a Xamarin.Forms project and selected Master-Detail template.
Once it was created, I simply debug it (F5) and I see the test app in the Android emulator. Everything works fine.
Today, I try to run the app again, I have changed absolutely nothing in the code. I rebuild the solution and it builds successfully.
When I run the app, it fails for this reason:
1>Starting deployment to Android_Accelerated_x86_Oreo ...
1>Starting emulator Android_Accelerated_x86_Oreo ...
1>C:\Program Files (x86)\Android\android-sdk\emulator\emulator.EXE -no-boot-anim -avd Android_Accelerated_x86_Oreo -prop monodroid.avdname=Android_Accelerated_x86_Oreo
1>emulator: ERROR: This AVD's configuration is missing a kernel file! Please ensure the file "kernel-qemu" is in the same location as your system image.
1>emulator: ERROR: ANDROID_SDK_ROOT is undefined
1>Emulator Android_Accelerated_x86_Oreo cannot be started.
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
The only solutions I have found deal with Android Studio, but I'm using Visual Studio 2019.
What can the issue be?

System.IO.IOException during the build process in VisualStudio 2017

I'm working on a Hololens application using Unity 2018.2.20f1. I'm building the application for UWP from Unity without a problem. However, after opening up the generated solution in the VisualStudio 2017 (Community Edition) and trying to build it, the build process fails with the following errors:
Severity Code Description Project File Line Suppression State
Error MSB3073 The command ""D:\Projects\VSProjects\VirtualPrague\Il2CppOutputProject\\IL2CPP\build\il2cpp.exe" --libil2cpp-static --compile-cpp -architecture=x86 -configuration=Release -platform=winrt -outputpath="D:\Projects\VSProjects\VirtualPrague\\build\bin\Win32\Release\GameAssembly.dll" --data-folder="D:\Projects\VSProjects\VirtualPrague\\build\bin\Win32\Release\\" -cachedirectory="D:\Projects\VSProjects\VirtualPrague\\build\obj\il2cppOutputProject\Win32\Release\\" -generatedcppdir="D:\Projects\VSProjects\VirtualPrague\Il2CppOutputProject\\Source" --additional-defines=WINDOWS_UWP --additional-defines=UNITY_UWP --additional-defines=UNITY_WSA_10_0 --additional-defines=UNITY_WSA --additional-defines=UNITY_WINRT --additional-defines=PLATFORM_WINRT -dotnetprofile=unityjit -verbose --map-file-parser="D:\Projects\VSProjects\VirtualPrague\Il2CppOutputProject\\IL2CPP\MapFileParser\MapFileParser.exe"" exited with code -532462766. Il2CppOutputProject C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets 44
and
Severity Code Description Project File Line Suppression State
Error LNK1181 cannot open input file 'D:\Projects\VSProjects\VirtualPrague\build\bin\Win32\Release\GameAssembly.lib' VirtualPrague D:\Projects\VSProjects\VirtualPrague\VirtualPrague\LINK 1
In the output there are multiple exceptions, similar to this one:
1>il2cpp.exe didn't catch exception: System.IO.IOException: The process cannot access the file 'C:\Users\dev\AppData\Local\Temp\tmpDE97.tmp' because it is being used by another process.
1> at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1> at System.IO.File.InternalDelete(String path, Boolean checkHost)
1> at Unity.IL2CPP.Shell.Execute(ExecuteArgs executeArgs, IExecuteController controller)
1> at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext)
1> at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
1> at il2cpp.Program.DoRun(String[] args)
1> at il2cpp.Program.Run(String[] args)
1> at il2cpp.Program.Main(String[] args)
The exceptions are the same but were thrown for different files. I tried to reinstall the Visual Studio and managed to get a build. The next day I turned on the PC and this error was back. I stopped all of the VS instances and processed from the task manager, deleted all of the files from the Temp folder and managed to get a build a couple more times. Then this error came back.
From what I can tell, during the build process, Visual Studio creates some *.tmp files and for some reason thinks that another process is using it.
Any idea why this is happening and how can it be solved?
Thanks a lot!
Edit: So here is what I did so far (this is more of a work around rather then a solution)
Uninstall vs and unity
Clear the registry with ccleaner and Advanced Uninstaller Pro
Install vs and Unity
Every time I want to get a build I,
Close all of vs instances
Clear Temp folder (C:\Users\dev\AppData\Local\Temp)
Delete previous vs solution
Build from Unity
Run vs as Administrator
Build and deploy the solution from vs
And it works for the most the time. Also, changing the solution configuration (from debug to release and vice versa) helps sometimes.

Intermitent out of memory xamarin android

I am using Visual studio on windows to debug on my android device. I already cranked up the heap to 1G and added android:largeHeap="true" to the manifest in the application node.
Sometime I am able to start the debugger.. IN other times it will stop to the java.lang.OOM error. If I press Debug again.. it works.
How can I make it works everytime ?
here is the error:
Severity Code Description Project File Line Suppression State
Error XA5213: java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize). Java ran out of memory while executing 'java.exe -Xmx1G -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\26.0.2\lib\dx.jar" --dex --no-strict --output obj\Debug\MonoAndroid90\android\bin C:\Users\cpu\Desktop\programmation\my-project\project\obj\Debug\MonoAndroid90\android\bin\classes.zip "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v9.0\mono.android.jar" obj\Debug\MonoAndroid90\lp\10\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\12\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\13\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\14\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\15\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\16\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\17\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\18\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\19\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\20\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\21\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\22\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\23\jl\bin\classes.jar obj\Debug\MonoAndroid90\lp\24\jl\classes.jar obj\Debug\MonoAndroid90\lp\25\jl\classes.jar obj\Debug\MonoAndroid90\lp\26\jl\classes.jar obj\Debug\MonoAndroid90\lp\27\jl\classes.jar obj\Debug\MonoAndroid90\lp\28\jl\classes.jar obj\Debug\MonoAndroid90\lp\29\jl\classes.jar obj\Debug\MonoAndroid90\lp\3\jl\okhttp-2.4.0.jar obj\Debug\MonoAndroid90\lp\30\jl\classes.jar obj\Debug\MonoAndroid90\lp\31\jl\classes.jar obj\Debug\MonoAndroid90\lp\4\jl\okio-1.5.0.jar obj\Debug\MonoAndroid90\lp\5\jl\picasso-2.5.2.jar obj\Debug\MonoAndroid90\lp\7\jl\arch-core-common.jar obj\Debug\MonoAndroid90\lp\8\jl\arch-lifecycle-common.jar obj\Debug\MonoAndroid90\lp\9\jl\bin\classes.jar' 0
It may be Picasso.. but I use it like this in my code so it shouldn't cause a problem with the memory I think:
Picasso.With(activity)
.Load(url)
.Fit()
.MemoryPolicy(MemoryPolicy.NoCache)
.MemoryPolicy(MemoryPolicy.NoStore)
.Into(image);

"The process cannot access the file 'Default.rd.xml' because it is being used by another process." on AppVeyor CI

I am doing some work on cordova-windows (https://github.com/apache/cordova-windows), which is using AppVeyor for testing on Windows. One of the things that was missing, were tests with Visual Studio 2017 (only VS2015 was used to test before). So I added those and it works like a charm - mostly.
Unfortunately we now have a very strange test failure:
https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-windows/build/1.0.458
Started
Creating Cordova Windows Project:
Path: testcreate 応用
Namespace: com.test.app
Name: 応用
Windows project created with cordova-windows#5.1.0-dev
Building project: C:\projects\cordova-windows\testcreate 応用\CordovaApp.Windows10.jsproj
Configuration : release
Platform : x64
Patching 10 in prebuild event...
Injected base.js reference to the www/index.html
Removing /( *)(<script\s+(?:type="text\/javascript"\s+)?src="\/\/Microsoft.WinJS.2.0\/js\/base.js">\s*<\/script>)(\s*)/ from www/index.html
Removing /( *)(<script\s+(?:type="text\/javascript"\s+)?src="\/\/Microsoft.Phone.WinJS.2.1\/js\/base.js">\s*<\/script>)(\s*)/ from www/index.html
CordovaApp.Windows10 -> C:\projects\cordova-windows\testcreate ??\build\windows\release\x64\win10\CordovaApp.Windows10_1.0.0.0_x64.appx
CordovaApp.Windows10 -> C:\projects\cordova-windows\testcreate ??\build\windows\release\x64\win10\Upload\CordovaApp.Windows10_1.0.0.0_x64.appx
CordovaApp.Windows10 -> C:\projects\cordova-windows\testcreate ??\AppPackages\CordovaApp.Windows10_1.0.0.0_Test\CordovaApp.Windows10_1.0.0.0_x64.appxbundle
CordovaApp.Windows10 -> C:\projects\cordova-windows\testcreate ??\AppPackages\CordovaApp.Windows10_1.0.0.0\CordovaApp.Windows10_1.0.0.0_x64.appxbundle
CordovaApp.Windows10 -> C:\projects\cordova-windows\testcreate ??\AppPackages\CordovaApp.Windows10_1.0.0.0_x64_bundle.appxupload
Your package has been successfully created.
Building project: C:\projects\cordova-windows\testcreate 応用\CordovaApp.Windows10.jsproj
Configuration : release
Platform : x86
Patching 10 in prebuild event...
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2975,5): error MSB3231: Unable to remove directory "build\windows\bld\PackageUploadLayout\". The process cannot access the file 'Default.rd.xml' because it is being used by another process. [C:\projects\cordova-windows\testcreate ??\CordovaApp.Windows10.jsproj]
C:\projects\cordova-windows\testcreate 応用\cordova\node_modules\q\q.js:155
throw e;
^
Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe: Command failed with exit code 1
at ChildProcess.whenDone (C:\projects\cordova-windows\testcreate 応用\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
The relevant part is this:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2975,5): error MSB3231: Unable to remove directory "build\windows\bld\PackageUploadLayout\". The process cannot access the file 'Default.rd.xml' because it is being used by another process. [C:\projects\cordova-windows\testcreate ??\CordovaApp.Windows10.jsproj]
This is not happening when I run the tests locally, meaning I can in no way reproduce what is going on here.
Any idea what process could block this Default.rd.xml file or build\windows\bld\PackageUploadLayout\?
How can I find out in a CI environment like AppVeyor?
Update:
Investigated a bit more by adding /clp:Verbosity=normal to the msbuild calls that are executed.
It runs a similar msbuild call 3 times (once per architecture). The first one succeeds, but during the second one the failure occurs. Makes sense as in the first iteration the folder doesn't exist yet, which it confirms with this output: Directory "build\windows\bld\PackageUploadLayout\" doesn't exist. Skipping..
The last output before the failure then is Removing directory "build\windows\bld\PackageUploadLayout\". which matches what we get in the error message. No indicator why the removing doesn't work though.
Super strange: With /clp:Verbosity=detailed added to the msbuild call, the build actually succeeds! My guess: Because the output takes time, whatever is having a lock on the folder or file releases it.
This is not exactly an answer, but rather investigation report. It is just not enough room comments to describe it. Here is what I did:
forked your repo
created AppVeyor project
added RDP
connected with RDP
installed procmon
added filter to monitor objects which path ends with bld\PackageUploadLayout\Properties\Default.rd.xml
run npm test manually from CMD
When the same error happened I see this:
I am not sure I understand why msbuild failed this way. I opened SHARING VIOLATION event, switched to process and see this:
What catches my eye is that msbuild version is 14. Should be 15 on Visual Studio 2017 image. We have version 14 installed for specific scenarios but default one is 15 (run where msbuild and you will see C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe). I am not sure where this path is set in your scripts, but I feel if you make it run correct msbuild version this may help.

Resources