gradle/gradle · error · GradleException
Create static archive failed: could not delete previous arch
Error message
Create static archive failed: could not delete previous archive
What it means
ArStaticLibraryArchiver deletes the previous static archive (.a) before re-archiving so stale object files cannot survive; if File.delete() returns false it throws GradleException 'Create static archive failed: could not delete previous archive'. The old archive is effectively locked or not deletable by the build user.
Source
Thrown at platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/gcc/ArStaticLibraryArchiver.java:57
public class ArStaticLibraryArchiver extends AbstractCompiler<StaticLibraryArchiverSpec> {
public ArStaticLibraryArchiver(BuildOperationExecutor buildOperationExecutor, CommandLineToolInvocationWorker commandLineToolInvocationWorker, CommandLineToolContext invocationContext, WorkerLeaseService workerLeaseService) {
super(buildOperationExecutor, commandLineToolInvocationWorker, invocationContext, new ArchiverSpecToArguments(), false, workerLeaseService);
}
@Override
public WorkResult execute(final StaticLibraryArchiverSpec spec) {
deletePreviousOutput(spec);
return super.execute(spec);
}
private void deletePreviousOutput(StaticLibraryArchiverSpec spec) {
// Need to delete the previous archive, otherwise stale object files will remain
if (!spec.getOutputFile().isFile()) {
return;
}
if (!spec.getOutputFile().delete()) {
throw new GradleException("Create static archive failed: could not delete previous archive");
}
}
@Override
protected Action<BuildOperationQueue<CommandLineToolInvocation>> newInvocationAction(final StaticLibraryArchiverSpec spec, List<String> args) {
final CommandLineToolInvocation invocation = newInvocation(
"archiving " + spec.getOutputFile().getName(), spec.getOutputFile().getParentFile(), args, spec.getOperationLogger());
return new Action<BuildOperationQueue<CommandLineToolInvocation>>() {
@Override
public void execute(BuildOperationQueue<CommandLineToolInvocation> buildQueue) {
buildQueue.setLogLocation(spec.getOperationLogger().getLogLocation());
buildQueue.add(invocation);
}
};
}
@OverrideView on GitHub (pinned to 534f27719b)
Solutions
- Delete the stale archive manually (or run gradle clean for that module) and re-run the build
- Exclude the project and build directories from antivirus/real-time scanning and file indexing on Windows
- Fix ownership/permissions of the build output directory so the build user can unlink files (chmod/chown on the build dir)
Defensive patterns
Strategy: fallback
Validate before calling
// Before building, prove the previous archive is deletable
val archive = layout.buildDirectory.file("lib/main.a").get().asFile
if (archive.isFile && !archive.delete()) {
throw GradleException("$archive is locked — close processes holding it or fix permissions, then rebuild")
} Prevention
- Exclude project and build directories from antivirus real-time scanning on Windows
- Run gradle --stop before deep toolchain/permission changes so no daemon keeps handles open
- Give the CI user ownership of build directories; avoid sharing them across users or containers
When it happens
Trigger: A stale .a output file exists and delete() fails: on Windows the file is open in another process (antivirus, indexer, archive tool, a still-running compiler); on Linux permissions/ownership deny unlink, or the directory is read-only.
Common situations: Windows builds with real-time antivirus scanning build outputs; a previous build's process still holding the file; build directories shared between users/containers with mixed ownership; network file systems.
Related errors
- Unable to get system memory
- Do not know how to unexport a main symbol on {operatingSyste
- Could not find 'cygpath' executable in path: {path}
- Could not open %s.
- Failed to initialize %s
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/1e8950a45c24e9da.
Report an issue: GitHub.