Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Recover Deleted Files in Android Studio

· 6 min read · Home Tech

In this article
  1. What Local History Actually Does
  2. Step-by-Step: Recover a Deleted File with Local History
  3. Other Built-In Recovery Options
  4. When Local History Fails: File System Recovery
  5. External Recovery Tools: What Actually Works
  6. Prevention: Stop Losing Files in the First Place
  7. Frequently Asked Questions

If you deleted a file or folder inside an Android Studio project and need it back, the quickest fix is Local History, a built-in feature that snapshots every change you make. Right-click the project or file in the Project view, choose Local History > Show History, select the version you want, and click Revert. This works for files deleted in the last few days (or longer, depending on your IDE settings) and requires no external tools.

What Local History Actually Does

Android Studio (built on IntelliJ IDEA) keeps a silent, time-stamped copy of every file you edit, create, or delete while the IDE is open. It is not a version-control system like Git — it has no branches, no commit messages, and no sharing. It simply stores a local cache of file states on your machine, typically under the .idea folder or in the IDE's system directory. Whenever you save a file, Android Studio records the previous version; when you delete a file, it records the state right before deletion.

The retention period is controlled by a setting called Local History: retention days, which defaults to 5 days in most installations. You can change it in File > Settings > Appearance & Behavior > System Settings > File History (on macOS, Android Studio > Preferences). Increasing this to 10 or 30 days gives you a longer safety net, at the cost of disk space.

Step-by-Step: Recover a Deleted File with Local History

  1. In the Project view (left panel), right-click the package or folder where the deleted file used to live.
  2. Select Local History > Show History.
  3. A panel opens on the right, showing a timeline of changes. Click a timestamp that predates the deletion.
  4. In the diff view, you'll see the file's content. If it's the version you want, click the Revert button in the top-right corner.
  5. Android Studio recreates the file in its original location. If the file was in a package, the package is recreated too.

If you don't see Local History in the context menu, make sure you're right-clicking inside the Project tool window, not on an editor tab. Also, Local History only works for files that were saved at least once — files that were created and deleted without ever being saved may not appear.

Other Built-In Recovery Options

Before reaching for external tools, check these Android Studio features:

  • Scratches and Consoles — If you accidentally deleted a scratch file (temporary notes), they're stored separately and can often be recovered from Scratches in the Project view.
  • Version Control (VCS) — If you use Git, SVN, or Mercurial, deleted files can be restored with git checkout -- <file> or git restore <file> (if the deletion wasn't committed) or git revert (if it was). Android Studio's VCS menu has a Local Changes tab that shows uncommitted deletions — right-click and choose Revert.
  • IDE Backup — Android Studio can create full project backups via File > Export to Zip, but only if you did this before the deletion.

When Local History Fails: File System Recovery

If the file was deleted outside Android Studio (e.g., in the OS file manager), or if Local History was disabled or cleared, your next option is the operating system's own recovery tools:

  • Windows: Check the Recycle Bin first. If it's empty, you can try File History (if enabled) or Previous Versions via the file's Properties tab.
  • macOS: Look in Trash. If the file was deleted with rm in Terminal, it won't go to Trash — you'd need a third-party recovery tool like Disk Drill or TestDisk.
  • Linux: Most desktop environments have a trash folder, but command-line deletions bypass it. Tools like extundelete or photorec can scan the disk, but they require the partition to be unmounted or read-only to avoid overwriting.

Important: stop using the computer immediately after a file-system-level deletion. Writing new data can overwrite the deleted file's blocks, making recovery impossible.

External Recovery Tools: What Actually Works

For files deleted from disk (not just from the IDE), third-party tools can help, but results vary:

  • TestDisk — Free, open-source, command-line. Excellent for recovering lost partitions and files from FAT/NTFS/ext4. Steep learning curve.
  • PhotoRec — Companion to TestDisk, focuses on file carving (recovering files by their signatures). It can find files even if the directory entry is gone, but filenames may be lost.
  • Recuva — Windows-only, free for basic use. Good for simple deletions on NTFS drives.
  • Disk Drill — Cross-platform, user-friendly, but free version only recovers up to 2 GB.

None of these tools are Android Studio-specific; they work on the raw disk. They cannot recover files from solid-state drives (SSDs) as reliably as from hard drives, because SSDs use TRIM, which permanently erases deleted data blocks almost immediately.

Prevention: Stop Losing Files in the First Place

The best recovery is the one you never need. Adopt these practices:

  • Use Git from day one — Even a local repository (no remote) lets you revert any change, including deletions. Commit frequently.
  • Increase Local History retention — Set it to 30 days in Settings.
  • Back up your project — Android Studio can automatically back up to a cloud service (if configured), or you can manually zip the project folder weekly.
  • Be careful with Refactor > Delete — This permanently deletes files from disk (bypassing the Recycle Bin) and removes them from version control if you choose that option.

Frequently Asked Questions

Can I recover a file deleted before I opened Android Studio today?

Yes, if the file was deleted while the IDE was running and the Local History retention period hasn't expired. The history is stored on disk, not in memory, so it survives IDE restarts. However, if you deleted the file from the OS file manager, Local History may still have a copy if the file was saved in the IDE before — the IDE records every save, not just deletions.

Does Local History work for files in the build folder?

No. The build folder is generated output; Android Studio excludes it from Local History by default. If you accidentally delete a generated file, just rebuild the project (Build > Make Project) to regenerate it.

Why is Local History missing from my context menu?

Local History is disabled if you're using a read-only project or if the IDE fails to create its system directory. Check that you have write permissions to the project folder and that the IDE's cache directory (usually ~/.AndroidStudioX.X/system) exists. You can also re-enable it in Settings > Appearance & Behavior > System Settings > File History.

Can I recover a file that was never saved?

No. Local History only records saved states. If you created a new file, typed content, and then deleted it without pressing Ctrl+S (or Cmd+S), no snapshot exists. Your only hope is an autosave plugin or the OS-level recovery tools, which are unlikely to help for unsaved data.

Is there a way to recover a deleted module or entire project?

If you deleted a module from the IDE, Local History can restore the module's files if they were saved. Right-click the parent project and use Local History > Show History, then find the state before the module was removed. For a whole project deleted from disk, use OS-level recovery tools or your version control remote.

Does Android Studio have an undo for file deletion?

Yes, but only if you haven't closed the IDE or performed many other actions. Press Ctrl+Z (or Cmd+Z) immediately after deleting a file in the Project view often restores it. However, this is unreliable after other operations, so Local History is the safer method.