What this issue means:
The root cause of this problem is antivirus software (such as Windows Defender) preventing resources from being embedded in the EXE by locking either the resource file, or the installer EXE (MyAppInstaller_xxx.exe).
Try these workarounds:
1) If you are compiling / packaging on a network file system or external drive, the easiest fix is to specify an output directory that is on a local filesystem. As an example of doing this, when using mcc command, use the option "-d" with a local directory when compiling, as follows:
2) Work with your IT helpdesk to either disable the antivirus software temporarily if possible, or to configure the antivirus software to not scan the executables in the output folders.
3) Deliver the application and MATLAB Runtime separately. Instead of generating the installer, only compile the standalone application (using the "mcc" or "mcc -C" command or compiler.build.* functions).
Further Troubleshooting:
Capture Process Monitor Log
If you want to diagnose if the file is really being locked and find out which program is locking the file, you could record the process monitor log to debug the issue.
Steps on using Process Monitor:
- Download Process Monitor from the following link: https://docs.microsoft.com/en-us/sysinternals/downloads/procmon, and unzip the archive to the location of your choice.
- Open up MATLAB and close all other applications.
- Click on Procmon.EXE in the unzipped location to open.
- Prepare for capturing events:
- On the top left, go to File -> Uncheck "Capture Events"
- Go to Edit -> Clear Display
- Go to Filter -> Reset Filter
The next three steps are time-sensitive as ideally, we would like Process Monitor to capture as narrow of a time window around the compiling issue as possible. Please read through the steps before proceeding:
- Capture events:
- Go back to File -> Capture Events and turn it back on/enable capture.
- Go back to MATLAB and retry the compiling and package workflow that resulted in the error message
- Once you reach the point in the workflow right after where the error message appears, go back to Process Monitor -> File -> Uncheck "Capture Events"
- Click on the Save icon (looks like a floppy disk) on the top right. Use the following parameters: Events to save -> All events, Format -> Native Process Monitor Format, Path -> (your choice). Please do NOT filter the Process Name to matlab.exe. Because we want to see what else processes are also accessing the installer or app file.
Process Monitor Log Analysis:
After capturing the log file, you can set the filter Path, contains, "for_redistribution" or "for_testing" (this depends on which folder is being reported in the error message) , Include.
Look around this process, and locate any other process that is suspicious. Namely non-MathWorks process. For example, you can use an exclude filter to find non-MathWorks process: In this example, "RepMgr.exe" was locking "MyAppInstaller_mcr.exe", and resulting this issue. Following is another example showing MsSense.exe was resulting this issue. Notice that the process that actually resulting the issue may not have "SHARING VIOLATION" as the result. Below example shows the error occuring for the for_testing folder. There are two other processes accessing the testApp.exe: