Bug 60992 - File is locked by another process
Summary: File is locked by another process
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 8.1 (15.5)
Hardware: PC Windows
: Highest blocker
Target Milestone: 15.5.2
Assignee: dean.ellis
URL:
: 61015 ()
Depends on:
Blocks:
 
Reported: 2017-12-05 23:21 UTC by Wally McClure
Modified: 2018-01-04 14:28 UTC (History)
23 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Wally McClure 2017-12-05 23:21:13 UTC
I am getting the error below when I compile and start to deploy to either a device or an emulator session.  This occurs under one of two circumstances.
1.  The connection to my device gets severed for a moment.  Loose cable or something.
2.  When i change from debugging against one emulator to a different one.  Say, I am using an android 5 emulator session.  I stop debugging, switch to another emulator (say Android 6), and then attempt to start a debug session there.

this is currently happening to me on when I have a xamarin forms shared app and am debugging in windows with visual studio 2017.

Severity	Code	Description	Project	File	Line	Suppression State
Error		error: error while writing anim: obj\Debug\android\bin\classes\android\support\compat\R$anim.class (The process cannot access the file because it is being used by another process)
    public static final class anim {	BWD.Mobile.XForms.Android	E:\BWDCore\BWD.Mobile.XForms\BWD.Mobile.XForms\BWD.Mobile.XForms.Android\obj\Debug\android\src\android\support\compat\R.java	11
Comment 1 Delbert Matlock 2017-12-06 12:06:35 UTC
I'm getting hit with this error for the "R$anim.class" as well.  Started after updating to Visual Studio 2017 15.5.  In my case, this error happens if I cancel a stalled deployment and then try to run it again.  This is for a stock Android app, not a Xamarin Forms app.

I've tried updating to the latest Android build tools with no luck.  I have not been successful in starting an app in the emulator since the update.
Comment 2 Bernd Stoltefuss 2017-12-06 13:14:16 UTC
Same here. Happens for me when running the app for the second time or when build fails due to an error. R$anim.class is locked.
I can also see lots of stale msbuild.exe processes (killing them will sometimes unlock the file).
Comment 3 Martin Bosansky 2017-12-06 14:21:55 UTC
I have the same error. Restarting VS2017 helps me.
Comment 4 Jon Douglas [MSFT] 2017-12-07 02:03:32 UTC
We are looking into this issue here: https://developercommunity.visualstudio.com/content/problem/155693/xamarin-android-project-cannot-build-because-ranim.html Please feel free to upvote for more visibility.
Comment 5 dean.ellis 2017-12-07 10:38:26 UTC
*** Bug 61015 has been marked as a duplicate of this bug. ***
Comment 6 Martin Bosansky 2017-12-07 13:55:11 UTC
When I restart both MSBuild.exe and VBCSCompiler.exe it helps me for a long time (few hours).
Comment 7 Jon Douglas [MSFT] 2017-12-08 18:01:08 UTC
Setting status to IN_PROGRESS as we are actively investigating the cause as we can reproduce on 15.5. Most updates will be on the Developer Community page as they are found. I will try to update this bug accordinly as well with proper status updates:

https://developercommunity.visualstudio.com/content/problem/155693/xamarin-android-project-cannot-build-because-ranim.html
Comment 8 joeperkins 2017-12-09 17:09:02 UTC
Updating to Xamarin 4.8.0.754 (2a34af5) appears to have fixed the issue.
Comment 9 Christopher Drosos 2017-12-10 14:27:21 UTC
and how can we get this freaking Xamarin 4.8.0.754 version??
Comment 10 stemis 2017-12-10 15:34:11 UTC
You can upgrade by uninstalling the Xamarin extension in VS and then reinstalling it.

However, the new version does NOT fix this issue, I still have it on 4.8.0.754
Comment 11 Daniel Vaughan 2017-12-10 15:39:06 UTC
The error I receive is:
error: error while writing AlertDialog_IDialogInterfaceOnCancelListenerImplementor: obj\Debug\android\bin\classes\android\support\v7\app\AlertDialog_IDialogInterfaceOnCancelListenerImplementor.class (The process cannot access the file because it is being used by another process)
Comment 12 Adroit 2017-12-10 15:42:58 UTC
Just type this in Package Manager Console: Stop-Process -processname MSBuild

Haha in my situation, it worked and I got archived apk.
Comment 13 Daniel Vaughan 2017-12-10 16:40:11 UTC
That's not it for me. That process isn't running. I receive an error:
Cannot find a process with the name "MSBuild"
Comment 14 Christopher Drosos 2017-12-10 17:03:57 UTC
sometimes the file is not locked by MSBuild but by Microsoft Visual Studio 2017
Comment 15 joeperkins 2017-12-10 18:39:00 UTC
Updating to Xamarin 4.8.0.754 (2a34af5) did not fix the issue.
Comment 16 Wil Dobson 2017-12-11 23:45:22 UTC
This happens for me while building the monodroid-samples/wear/Quiz solution. Happens every time, even after day of not using VS 2017 preview.

Specific error: 
error: error while writing anim: obj\Debug\android\bin\classes\android\support\compat\R$anim.class (The process cannot access the file because it is being used by another process)
    public static final class anim {	Quiz	C:\Repos\monodroid-samples\wear\Quiz\Wearable\obj\Debug\android\src\android\support\compat\R.java	11	

Deleting BIN and OBJ folders before build doesn't resolve this, which has been my usual fix for corrupted build output.
Comment 17 danielferenczi 2017-12-12 17:41:15 UTC
Same problem for me. After updating to VS 2017 15.5.
Comment 18 Jay 2017-12-12 22:31:02 UTC
Same problem with Xamarin 4.8.0.753.
Comment 19 danielferenczi 2017-12-13 13:02:49 UTC
Hi guys I know that people previously posted about this link:

https://developercommunity.visualstudio.com/content/problem/155693/xamarin-android-project-cannot-build-because-ranim.html

here in the thread but there is an updated soulution (still a workaround) that worked for me. So far no file has been locked by other processes. Check it out!
Comment 20 Jon Douglas [MSFT] 2017-12-14 19:16:08 UTC
This is resolved in Visual Studio 2017 15.5.2. You can read the release notes here:

https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#15.5.2

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#8-1-0-25
Comment 21 post4me3 2017-12-15 20:11:45 UTC
I've upgraded to 15.5.2 as this apparently was the recommended path to fix the :
"Xamarin Android project cannot build because R$anim.class is in use"

issue.

However - now I cannot build ANY Android projects as when I open VS 2017 and open a project containing my DROID project - all of the previous toolbar and menu items relating to android have now vanished. There is no TOOLS->Android menu item. It appears when you open VS without loading a solution but once a solution is loaded - you get the issue.

Examining the Xamarin Logs we now get :

Xamarin.VisualStudio.ProjectFixerService|Error|0|System.InvalidOperationException: This property is not valid when the SDK is not installed
   at Xamarin.AndroidTools.AndroidSdk.ValidatePath(String path) in C:\d\lanes\5409\6575bd11\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Xamarin.AndroidTools\AndroidSdk.cs:line 263
   at Xamarin.AndroidTools.AndroidSdk.get_AndroidExe() in C:\d\lanes\5409\6575bd11\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Xamarin.AndroidTools\AndroidSdk.cs:line 145
   at Xamarin.VisualStudio.Android.Services.AndroidToolsSdk.get_IsInstalledAndroidExe() in C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.Android\Services\AndroidToolsSdk.cs:line 284
   at Xamarin.VisualStudio.Android.Services.AndroidToolsSdk.get_IsInstalled() in C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.Android\Services\AndroidToolsSdk.cs:line 439
   at Xamarin.VisualStudio.Android.ProjectSystem.Fixers.AndroidTargetFrameworkVersionFixer.ShouldExecute(IProjectFixerContext context) in C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.Android\ProjectSystem\Fixers\AndroidTargetFrameworkVersionFixer.cs:line 21
   at Xamarin.VisualStudio.Android.ProjectSystem.MonoAndroidProjectFixerBase.FixupProject(IProjectFixerContext context) in C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.Android\ProjectSystem\Fixers\MonoAndroidProjectFixerBase.cs:line 14
   at Xamarin.VisualStudio.ProjectFixerService.FixupProject(String projectFileName) in C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio\Fixers\ProjectFixerService.cs:line 42

When I go to options->Xamarin->Android Settings  - I have valid values/directories for :

a) Java Development Kit Location
b) Android SDK Location
c) Android NDK Location

Is there a rollback of VS 15.5.2 that a) Fixes this issue and b) Fixes the issue that 15.5.2 was suppose to fix ?
Comment 22 Daniel Vaughan 2017-12-15 20:17:00 UTC
I reported this issue on a private forum related to the VS installer. 
It appears that the Visual Studio Installer sometimes uninstalls the Android SDK, but unlike you I did not see the Android SDK directories remaining. I restored the Android components by launching the Visual Studio Installer and reselecting the Xamarin Android components.
Comment 23 Daniel Vaughan 2017-12-15 20:24:43 UTC
I should have stated in my last message that I was referring directly to the comment by post4me3@gmail.com and it relates to a different issue.
As far as I have experienced, the file locking issue has been resolved in 15.5.2.
Comment 24 post4me3 2017-12-15 20:35:59 UTC
Have tried to re install 15.5.2 via the installer and also tried reselecting the Android components again (as per Daniel's comment @23 - it does appear that the 15.5.2 installer deselects these) - However - after doing the above, same issue as before , zero Android coverage in VS 2017 Enterprise.
Comment 25 joeperkins 2017-12-15 22:31:44 UTC
This could be caused by the SDK path registry key missing, you should verify it exists and is correct.  

For 32 bit machines
HKEY_LOCAL_MACHINE\Software\Android SDK Tools\Path
 
For 64 bit machines
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Android SDK Tools\Path
Comment 26 joeperkins 2017-12-15 22:55:00 UTC
This issue is NOT fixed in Xamarin 4.8.0.756 (64d469412)

Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3

obj\Release\android\src\android\support\compat\R.java:11: error: error while writing anim: 

obj\Release\android\bin\classes\android\support\compat\R$anim.class (The process cannot access the file because it is being used by another process)
Comment 27 Jon Douglas [MSFT] 2017-12-16 00:33:10 UTC
(In reply to post4me3 from comment #21)
> I've upgraded to 15.5.2 as this apparently was the recommended path to fix
> the :
> "Xamarin Android project cannot build because R$anim.class is in use"
> 
> issue.
> 
> However - now I cannot build ANY Android projects as when I open VS 2017 and
> open a project containing my DROID project - all of the previous toolbar and
> menu items relating to android have now vanished. There is no TOOLS->Android
> menu item. It appears when you open VS without loading a solution but once a
> solution is loaded - you get the issue.
> 
> Examining the Xamarin Logs we now get :
> 
> Xamarin.VisualStudio.ProjectFixerService|Error|0|System.
> InvalidOperationException: This property is not valid when the SDK is not
> installed
>    at Xamarin.AndroidTools.AndroidSdk.ValidatePath(String path) in
> C:\d\lanes\5409\6575bd11\source\xamarinvs\External\md-addins\MonoDevelop.
> MonoDroid\external\androidtools\Xamarin.AndroidTools\AndroidSdk.cs:line 263
>    at Xamarin.AndroidTools.AndroidSdk.get_AndroidExe() in
> C:\d\lanes\5409\6575bd11\source\xamarinvs\External\md-addins\MonoDevelop.
> MonoDroid\external\androidtools\Xamarin.AndroidTools\AndroidSdk.cs:line 145
>    at
> Xamarin.VisualStudio.Android.Services.AndroidToolsSdk.
> get_IsInstalledAndroidExe() in
> C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.
> Android\Services\AndroidToolsSdk.cs:line 284
>    at
> Xamarin.VisualStudio.Android.Services.AndroidToolsSdk.get_IsInstalled() in
> C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.
> Android\Services\AndroidToolsSdk.cs:line 439
>    at
> Xamarin.VisualStudio.Android.ProjectSystem.Fixers.
> AndroidTargetFrameworkVersionFixer.ShouldExecute(IProjectFixerContext
> context) in
> C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.
> Android\ProjectSystem\Fixers\AndroidTargetFrameworkVersionFixer.cs:line 21
>    at
> Xamarin.VisualStudio.Android.ProjectSystem.MonoAndroidProjectFixerBase.
> FixupProject(IProjectFixerContext context) in
> C:\d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio.
> Android\ProjectSystem\Fixers\MonoAndroidProjectFixerBase.cs:line 14
>    at Xamarin.VisualStudio.ProjectFixerService.FixupProject(String
> projectFileName) in
> C:
> \d\lanes\5409\6575bd11\source\xamarinvs\src\Core\VisualStudio\Fixers\ProjectF
> ixerService.cs:line 42
> 
> When I go to options->Xamarin->Android Settings  - I have valid
> values/directories for :
> 
> a) Java Development Kit Location
> b) Android SDK Location
> c) Android NDK Location
> 
> Is there a rollback of VS 15.5.2 that a) Fixes this issue and b) Fixes the
> issue that 15.5.2 was suppose to fix ?

Please use Visual Studio's "Report a problem" feature to report this issue regarding the Android Components being uninstalled. This is a known issue that the installer team is looking into currently. This bug report is not the best place to talk about this issue and thus a new thread should be created. Thank you in advance!

https://docs.microsoft.com/en-us/visualstudio/ide/how-to-report-a-problem-with-visual-studio-2017
Comment 28 Jon Douglas [MSFT] 2017-12-16 00:34:33 UTC
(In reply to joeperkins from comment #26)
> This issue is NOT fixed in Xamarin 4.8.0.756 (64d469412)
> 
> Microsoft Visual Studio Professional 2015
> Version 14.0.25431.01 Update 3
> 
> obj\Release\android\src\android\support\compat\R.java:11: error: error while
> writing anim: 
> 
> obj\Release\android\bin\classes\android\support\compat\R$anim.class (The
> process cannot access the file because it is being used by another process)

Hi Joe,

Can you please also include your Xamarin.Android version as well? This should be included in 8.1.0.25

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#8-1-0-25
Comment 29 joeperkins 2017-12-16 01:08:26 UTC
I have 8.1.0.13 after installing the 15.5.2. 

I have installed 15.5.2 on multiple systems and the resulting Xamarin.Android versions are 8.1.0.13.

I guess 15.5.2 isant installing 8.1.0.25 when 8.1.0.25 is listed in the release notes.

https://releases.xamarin.com/service-release-15-5-2/

System information:

Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Professional

Visual C# 2015   00322-40000-00000-AA306
Microsoft Visual C# 2015

Visual C++ 2015   00322-40000-00000-AA306
Microsoft Visual C++ 2015

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   4.8.0.756 (64d469412)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.8.188 (c5813fa34)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android   8.1.0.13 (f241f51)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.Android SDK   8.1.0.23 (HEAD/f65f87747)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS   11.6.1.2 (6857dfc)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS and Xamarin.Mac SDK   11.6.1.2 (6857dfc)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Comment 31 Paul Diston 2018-01-04 14:28:13 UTC
I am also running into this issue on Visual Studio 2015, my Android version is 8.1.0.13.

When I check for updates it says "Xamarin is up to date!"