While developing Android applications, you may encounter build errors that prevent your project from compiling successfully. One common error is:
Execution failed for task ':app:mergeDebugJavaResource'.
Caused by:
java.nio.file.FileSystemException:
out.jar: The process cannot access the file because it is being used by another process.
This error can be frustrating, especially for beginners. Fortunately, the cause is usually simple: another application or process has locked a file that Android Studio needs during the build process.
In this article, we’ll explain what causes this problem and provide step-by-step solutions to fix it.
Understanding the Error
Android Studio uses Gradle to build your application. During the build process, Gradle creates temporary files inside the build directory.
One of these files may be:
app/build/intermediates/merged_java_res/debug/out.jar
If another process is using this file, Gradle cannot modify or overwrite it, causing the build to fail.
Typical error message:
java.nio.file.FileSystemException:
out.jar: The process cannot access the file because it is being used by another process.
Common Causes
1. Android Studio Background Process
Sometimes Android Studio itself keeps a file handle open during a previous build.
2. Gradle Daemon
The Gradle daemon may become stuck and continue locking generated files.
3. Antivirus Software
Windows Defender or third-party antivirus solutions often scan newly generated JAR files and temporarily lock them.
4. File Synchronization Tools
Applications such as:
- OneDrive
- Google Drive
- Dropbox
- Backup software
may monitor project folders and lock files while synchronizing them.
5. Java Processes Running in Background
Old Java or Gradle processes may still be running after a failed build.
Solution 1: Clean and Rebuild the Project
The simplest fix is often cleaning the project.
Using Android Studio
Select:
Build → Clean Project
Then:
Build → Rebuild Project
Using Command Line
gradlew clean
gradlew build
Solution 2: Delete the Build Folder
Close Android Studio.
Navigate to:
app/build/
Delete the entire build directory.
You can also remove:
.gradle/
from the project root.
Reopen Android Studio and rebuild the project.
Solution 3: Stop All Gradle Processes
Open Command Prompt:
gradlew --stop
This stops all running Gradle daemons.
You can then restart Android Studio and try building again.
Solution 4: Kill Java Processes
Open Task Manager.
Look for:
java.exe
javaw.exe
gradle.exe
Terminate any processes related to old Android Studio builds.
Alternatively, from Command Prompt:
taskkill /F /IM java.exe
taskkill /F /IM javaw.exe
Be careful if other Java applications are running.
Solution 5: Exclude the Project from Antivirus Scanning
Windows Defender is a common cause of file locking issues.
Add an Exclusion
Open:
Windows Security
Navigate to:
Virus & Threat Protection
→ Manage Settings
→ Exclusions
Add exclusions for:
C:\Users\YourUser\AndroidStudioProjects\
or the specific project folder.
This prevents Windows Defender from locking generated build files.
Solution 6: Disable Real-Time Synchronization
If your project is stored in:
OneDrive
Dropbox
Google Drive
move it to a local directory such as:
C:\Development\
Cloud synchronization software frequently causes build file locking.
Solution 7: Invalidate Android Studio Caches
Sometimes Android Studio’s internal cache becomes corrupted.
Navigate to:
File → Invalidate Caches
Select:
Invalidate and Restart
Android Studio will rebuild its indexes after restarting.
Solution 8: Restart the Computer
If you’re unsure which process is locking the file, a full system restart often clears the problem immediately.
This is especially effective after failed builds or IDE crashes.
Advanced Troubleshooting: Find the Process Locking the File
Microsoft provides a utility called Process Explorer.
Steps
- Download Process Explorer.
- Run as Administrator.
- Press:
Ctrl + F
- Search for:
out.jar
Process Explorer will show exactly which application is using the file.
You can then terminate the offending process.
Preventing Future Problems
To reduce the chance of encountering this issue:
- Keep Android Studio updated.
- Keep Gradle updated.
- Avoid storing projects in synchronized cloud folders.
- Exclude project directories from antivirus scanning.
- Regularly clean old build artifacts.
- Stop unused Gradle daemons.
Example Fix Workflow
When you encounter:
Execution failed for task ':app:mergeActivDebugJavaResource'
Follow this order:
- Close Android Studio.
- Run:
gradlew --stop
- Delete:
app/build/
.gradle/
- Reopen Android Studio.
- Clean Project.
- Rebuild Project.
In most cases, the issue is resolved immediately.
Conclusion
The “The process cannot access the file because it is being used by another process” error in Android Studio is usually caused by a file lock created by Gradle, Java, antivirus software, or synchronization tools.
Although the error looks intimidating, it is rarely related to your source code. By cleaning the project, stopping Gradle daemons, deleting build artifacts, and checking for applications that lock files, you can quickly restore normal builds and continue development.
Understanding how Android Studio, Gradle, and the Windows file system interact will help you diagnose similar build problems more efficiently in the future.


