---
title: "The Ultimate Fix: Lost Your Keystore Password but the IDE Still Remembers It? Catch It in the Build Log"
description: "The farthest distance in the world is when the password is right there in the IDE, and I can't see it"
author: "kidneyweakx"
published: 2025-12-06T12:00:00.000Z
updated: 2026-10-29T10:15:52.897Z
lang: en
tags: ["程式筆記", "Android"]
canonical: https://kidneyweakx.com/blog/catch-keystore-secret-by-gradle?lang=en
alternate_zh_tw: https://kidneyweakx.com/blog/catch-keystore-secret-by-gradle.md
alternate_ja: https://kidneyweakx.com/blog/catch-keystore-secret-by-gradle.md?lang=ja
---

# The Ultimate Fix: Lost Your Keystore Password but the IDE Still Remembers It? Catch It in the Build Log

> **The farthest distance in the world is when the password is right there in the IDE, and I can't see it**

I bet plenty of Android developers have hit this soul-crushing moment: you're about to build a Release version and realize you've forgotten the Keystore password you haven't typed in ages! Android Studio has thoughtfully checked "Remember passwords" and fills it in for you, but all it will ever show you is `••••••••`. It flat-out refuses to show the plaintext.

Is the only option to ask Google to reset your Upload Key, or to brute-force it?

Hold on! As long as Android Studio still remembers the password, we can "intercept" it through Gradle.

### How it works

When we run **Generate Signed Bundle / APK**, Android Studio has to "inject" the password into Gradle behind the scenes so Gradle can do the signing. All we have to do is plant a bit of code in `build.gradle` that listens for this injection, and we can print the password to the Log.

#### Steps (Kotlin DSL version)

Step 1: Plant the listener script

Open your app-level build.gradle.kts file and paste the following code at the very end of the file:

Kotlin

```
// ==========================================
// 密碼攔截腳本 (用完請務必刪除！！！)
// ==========================================
project.afterEvaluate {
    val storePass = project.properties["android.injected.signing.store.password"]
    val keyPass = project.properties["android.injected.signing.key.password"]

    if (storePass != null || keyPass != null) {
        println("\n========== [抓到了！密碼在這裡] ==========")
        println("Store Password: $storePass")
        println("Key Password:   $keyPass")
        println("=========================================\n")
    }
}

```

**Step 2: Trigger the build**

1. Click **Build** > **Generate Signed Bundle / APK...** in Android Studio's top menu.
2. Go through the normal flow and fill in the Keystore path.
3. **The key step:** make sure **"Remember passwords"** is checked (that's what makes the IDE cough up the password).
4. Click Next > Create to start the build.

Step 3: Check the Log

Once the build starts, open the Build tab at the bottom and click "Toggle view" (the list icon) on the left to switch to plain-text mode.

In the vast sea of Log output, search for the keyword: `抓到了`.

You'll see something like this:

Plaintext

```
========== [抓到了！密碼在這裡] ==========
Store Password: your_lost_password_123
Key Password:   your_lost_password_123
=========================================

```

Step 4: Back it up and destroy the evidence (most important!)

Congrats, you've got your password back!

1. Immediately save the password in 1Password or somewhere safe.
2. **Immediately delete** that code from `build.gradle.kts`.
3. If that code accidentally got committed to Git, be sure to rewrite your Git history, or treat the password as leaked.

***

#### Wrap-up

This trick uses Gradle's `project.properties` mechanism to read the parameters the IDE injects directly. No cracking tools to install, safe and fast. Hope it helps all my fellow goldfish-memory developers out there!
