You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

生成Signed APK时遇错误:Magic number不匹配求助

Fix for "Magic number did not match" Error When Generating Signed APK

Hey there, let's sort out this frustrating issue you're hitting when trying to generate a signed APK! That "Magic number did not match" error is directly tied to Android Studio's password storage system—specifically, the corrupted KeePass database it uses to save your keystore credentials. Here are practical, step-by-step fixes to get you back up and running:

1. Reset Android Studio's Credential Store

This is the most common fix for this exact error:

  • Close Android Studio entirely (make sure no background processes are running)
  • Navigate to the credentials folder based on your OS:
    • Windows: C:\Users\<YourUsername>\.AndroidStudio<YourVersion>\config\credentials
    • macOS: ~/Library/Application Support/Google/AndroidStudio<YourVersion>/credentials
    • Linux: ~/.AndroidStudio<YourVersion>/config/credentials
  • Delete all files in this folder (these are the corrupted KeePass database files)
  • Restart Android Studio, then try generating your signed APK again. You'll need to re-enter your keystore details this time, but the error should be gone.

2. Bypass the GUI with Gradle Command Line

If the IDE's GUI is still acting up, skip it and use Gradle directly—it's reliable:

  • Open the Terminal tab in Android Studio (bottom of the window)
  • Run this command (use gradlew.bat instead of ./gradlew if you're on Windows):
    ./gradlew assembleRelease
    
  • When prompted, input your keystore password, key alias, and key password
  • Your signed APK will be waiting for you in app/build/outputs/apk/release/

3. Update Android Studio

Sometimes this bug gets squashed in newer IDE versions:

  • Go to Help > Check for Updates (Windows/Linux) or Android Studio > Check for Updates (macOS)
  • Install any available updates, restart Android Studio, and try generating the APK again.

4. Invalidate Caches and Restart

Corrupted caches can sometimes cause weird issues like this:

  • Go to File > Invalidate Caches...
  • Check all the boxes, then click Invalidate and Restart
  • Let Android Studio rebuild your project from scratch, then attempt the signed APK generation again.

Why This Happens

This error typically pops up when the KeePass database that Android Studio uses to store saved passwords gets corrupted—this can happen from an unexpected IDE crash, a failed update, or minor file system glitches. Resetting the credential store forces the IDE to create a fresh, uncorrupted database.

内容的提问来源于stack exchange,提问作者mubashermubi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:26:08