title: Error: Execution failed for task ':app:clean'. Unable to delete file
body: <p>I'm trying to rebuild my Android Studio Gradle project (containing mostly Kotlin code), but it started to throw an <code>UnableToDeleteFileException</code> during the cleaning/rebuilding process:</p>
  
  <pre><code>Execution failed for task ':app:clean'.
  &gt; Unable to delete file: C:\Users\User\KotlinGameEngine\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\jars\classes.jar
  </code></pre>
  
  <p>This started happening after I tried to change my project's package structure. Unfortunately, I did it by renaming and moving the source folders rather than refactoring through Android Studio, which was a bad idea.</p>
  
  <p>I've been searching for a solution to this problem all day, and these are the things I have tried to no avail:</p>
  
  <ul>
  <li>Doing a Gradle sync;</li>
  <li>Reinstalling Java JRE and Java SDK;</li>
  <li>Reinstalling the latest version of Android Studio (1.4);</li>
  <li>Rolling back to the previous AS version (1.3);</li>
  <li>Invalidating the AS cache and restarting;</li>
  <li>Deleting the <code>gradle</code> and <code>.gradle</code> directories in the project directory;</li>
  <li>Deleting the <code>.gradle</code> directory in my user directory;</li>
  <li>Running <code>gradlew clean</code> from the AS terminal;</li>
  <li>Manually copying the sources over to a new project (weird that it somehow persists across projects...)</li>
  </ul>
  
  <p>Things that I've tried with a little success, but only let me perform one more clean and rebuild before the error occurs again:</p>
  
  <ul>
  <li>Closing AS, manually deleting the build files, and opening it again;</li>
  <li>Killing the <code>java.exe</code> process while AS is running (this could technically be done every time, but it's tedious and slows down the build process)</li>
  </ul>
  
  <p>So it seems that compile the Java process may put a lock on the build files for some reason, but it might also be something to do with Kotlin. I have a (more mature) Java Android project that I'm working on, though I can't reproduce this error when cleaning it. It seems to only happen to my Kotlin project.</p>
  
  <h2>Update:</h2>
  
  <p>I've found that the problem is being caused by the Kotlin Android plugin. The problem disappears when I remove <code>apply plugin: 'kotlin-android'</code> from the module's <code>build.gradle</code> file and comes back when I reinsert it. Feel free to offer any insight into this.</p>
  
  <h2>Update 2:</h2>
  
  <p>The last update isn't the cause. I found that if a project contains a Kotlin file then rebuilding and cleaning fails. It continues to fail, even if all the Kotlin files are removed, until the background Java process is killed, meaning it has some kind of lock on the build files. I submitted a bug here with more details and steps to reproduce the bug: <a href="https://youtrack.jetbrains.com/issue/KT-9440" rel="noreferrer" title="KT-9440">KT-9440</a></p>