Find SHA Keys in android studio
Finding Java Paths and SHA Keys for Android Development
No problem, that path can sometimes be in a different location depending on your Android Studio version or how it was installed. Let's find the exact path on your computer using a more reliable method.
Method 1: The Best Way (Find it Inside Android Studio)
This is the most foolproof method because Android Studio will tell you exactly which Java it is using.
Step 1
In Android Studio, go to File → Settings.
Step 2
In the Settings window, navigate to Build, Execution, Deployment → Build Tools → Gradle.
Step 3
On the right-hand side, look for a setting called Gradle JVM. It will have a dropdown menu. The path displayed there is the one you need.
Android Studio Settings Screenshot
Click on the dropdown and you will see the full path. It will look something like one of these:
C:\Program Files\Android\Android Studio\jbrC:\Program Files\Android\Android Studio\jreC:\Program Files\Android\Android Studio\jbr\bin- Or a path pointing to a specific version like
C:\Program Files\Android\Android Studio\jbr-17
Copy that full path. This is the correct location for your system.
Method 2: If You Can't Find it in Settings (Search Your PC)
If the settings method doesn't work for some reason, you can search for it.
Step 1
Open File Explorer.
Step 2
Go to This PC.
Step 3
In the search bar at the top right, type java.exe and press Enter.
Step 4
Wait for the search to complete. Look for a result that is inside a folder named Android Studio or JetBrains. The full path of that file is what you need.
Putting It All Together
Once you have found your correct path using one of the methods above, go back to your Terminal window in Android Studio.
Now, run the following commands. Replace the placeholder path with the one you just copied.
$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jbr"
(Make sure to use the path you found, and keep it inside the quotes)
$env:Path = "$env:JAVA_HOME\bin;" + $env:Path
After running those two commands, you can verify it worked by typing:
java -version
If you see the version information, you're all set! Now run the original command again:
.\gradlew.bat signingReport
This should now execute successfully.
Understanding Your App Signatures
Excellent! The command worked perfectly. You have successfully found your app's signatures.
Let's break down what this output means and what you need to do next.
What Your Output Tells Us
You have two important sections here: one for debug and one for release.
1. The debug Variant (For Testing)
This is the key you will use for testing your app links during development.
Variant: debug ... SHA-256: 33:06:1D:48:62:71:92:12:CE:69:03:EF:05 ...
This is the SHA-256 fingerprint you need for your assetlinks.json file right now.
2. The release Variant (For Production)
Variant: release Config: null Store: null Alias: null
This is a very important finding. It means you have not yet created a release signing key for your app. Every app published on the Google Play Store must be signed with a unique, private release key. The debug key is only for development.
What To Do Next: A Step-by-Step Plan
Step 1: Create Your assetlinks.json for Testing
You can use your debug key to create a test version of the file.
- Take your debug SHA-256 fingerprint.
- Remove all the colons (
:). - Place it in your
assetlinks.jsonfile.
Your assetlinks.json file should look like this:
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.app",
"sha256_cert_fingerprints":
["dfadlfakdkflkajfk114C605F061D4862719212CE6903EF05"]
}
}]
Note: I've removed the colons from the SHA-256, which is the correct format.
You can now upload this file to your server and test the app link functionality.
Step 2: Generate a Release Signing Key (Crucial for Production)
You must do this before you can publish your app. The easiest way is with Android Studio's built-in tool.
- In Android Studio, go to the menu bar and click Build → Generate Signed Bundle / APK....
- Select Android App Bundle and click Next.
- In the "Key store path" section, click Create new....
- Fill in the form:
- Key store path: Choose a safe location on your computer to save your key file (e.g., a folder named
Keysinside your project). Do not lose this file! If you lose it, you will not be able to update your app on the Play Store. - Password: Create a strong password for the keystore.
- Alias: A name for your key (e.g.,
release-key). - Password: Create a strong password for the key itself (can be the same as the keystore password).
- Validity (years): Set it to at least 25.
- Fill in at least one of the certificate fields (e.g., your name).
- Key store path: Choose a safe location on your computer to save your key file (e.g., a folder named
- Click OK. You will be back at the previous screen. You can now Cancel out of the "Generate Signed Bundle" wizard. The goal was just to create the key file.
A Simpler Way to Get SHA Keys
Yes, absolutely! There is a more direct and simpler way to get the SHA keys using a tool called keytool, which is part of the Java Development Kit (JDK) you just configured.
This method is simpler because it's a single, direct command that doesn't require running the entire Gradle build system.
Here are the two simple commands for your PowerShell terminal.
1. Simple Way to Get the Debug SHA-256 Key
This is the key you use for testing your app during development. You can run this command from any directory in your terminal.
Copy and paste this command into your PowerShell terminal and press Enter:
keytool -list -v -keystore "$env:USERPROFILE\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
What this command does:
keytool: The program that manages keystore files.-list -v: Lists the entries in the keystore with verbose details.-keystore "$env:USERPROFILE\.android\debug.keystore": Points to the standard location of the debug keystore on Windows (e.g.,C:\Users\YourName\.android\debug.keystore).-alias androiddebugkey: The standard name for the debug key.-storepass android&-keypass android: The standard passwords for the default debug keystore.
You will be prompted for a password, but since we included -storepass android, it will be entered automatically. Just look for the SHA-256 line in the output.
2. Simple Way to Get the Release SHA-256 Key
This is the key you need for your production app that you publish to the Google Play Store. You use this command after you have created your release keystore file (.jks).
- First, make sure you know the full path to your release key file (e.g.,
C:\Users\YourName\Keys\my-release-key.jks). - Copy and paste this command into your PowerShell terminal, replacing the path with your actual file path, and press Enter:
keytool -list -v -keystore "C:\path\to\your\my-release-key.jks"
Example:
keytool -list -v -keystore "C:\Users\YourName\Keys\my-release-key.jks"
You will then be prompted to enter the keystore password and the key password that you created when you generated the release key. After you enter them, the command will print the details, including the SHA-256 fingerprint.
Which One Should I Use?
- Use the Debug Key for setting up your initial
assetlinks.jsonfile and for testing on your development device or emulator. - Use the Release Key for the final version of your
assetlinks.jsonfile that will be used by your published app on the Play Store.
Best Practice: For your final assetlinks.json file, it's highly recommended to include both the debug and release SHA-256 fingerprints. This ensures your App Links work correctly for both development and production versions of your app.
Final Step: Update Your assetlinks.json for Production
For your final, production-ready assetlinks.json file, it is a best practice to include both fingerprints. This ensures your app links work for both debug and release versions of your app.
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.app",
"sha256_cert_fingerprints":
[
"akldjfdlkfldjflkjfadsklfjkd114C60532F061D4862719212CE6903EF05", // Debug fingerprint
"YOUR_RELEASE_SHA256_FINGERPRINT_HERE" // Add the new release one here
]
}
}]
Post a Comment