Compiling for ESP32 fails: "Access is denied."

OK, here you go:

  1. Use Arduino IDE Boards Manager to install version 2.0.10 of the esp32 boards platform if you already rolled back to a previous version.
  2. Select File > New Sketch from the Arduino IDE menus.
  3. Select any ESP32 board from the Arduino IDE Tools > Board menu.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to finish.
  6. Scroll the black output panel at the bottom of the Arduino IDE window all the way up to the top.
  7. Look for the line that starts with "Using board ...".
    For example:
    Using board 'esp32' from platform in folder: C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.10
    
  8. Use any text editor to open the file platform.txt that you find under the path shown in that line of the compilation output.
  9. Change line 192 of platform.txt from this:
    recipe.hooks.core.prebuild.set_core_build_flag.pattern=bash -c "echo '-DARDUINO_CORE_BUILD' > {file_opts.path}"
    
    to this:
    recipe.hooks.core.prebuild.set_core_build_flag.pattern=bash -c "echo -DARDUINO_CORE_BUILD > {file_opts.path}"
    
  10. Change lines 195-197 from this:
    recipe.hooks.prebuild.set_core_build_flag.pattern.windows=cmd /c type nul > {file_opts.path}
    recipe.hooks.core.prebuild.set_core_build_flag.pattern.windows=cmd /c echo "-DARDUINO_CORE_BUILD" > {file_opts.path}
    recipe.hooks.core.postbuild.set_core_build_flag.pattern.windows=cmd /c type nul > {file_opts.path}
    
    to this:
    recipe.hooks.prebuild.set_core_build_flag.pattern.windows=cmd /c type nul > "{file_opts.path}"
    recipe.hooks.core.prebuild.set_core_build_flag.pattern.windows=cmd /c echo "-DARDUINO_CORE_BUILD" > "{file_opts.path}"
    recipe.hooks.core.postbuild.set_core_build_flag.pattern.windows=cmd /c type nul > "{file_opts.path}"
    
  11. Save the file.
  12. Select File > Quit from the Arduino IDE menus.
  13. Start Arduino IDE.
    Restarting Arduino IDE is necessary to cause it to recognize the changes you made to the platform.txt file.

Now try compiling your sketch for an ESP32 board again. Hopefully this time the "Access is denied" error will no longer occur.