I have signed my app and exported it to a folder on my desktop called app in this folder is my app itself and the keystore. How do i find the key hash that i can copy into t
The solutions mentioned above didn't work for me for some reason but i was able to successfully generate keyhash. I am writing the 10 easiest step to get keyhash of your signed apk [apk signed with keystore]:
Copy the below code into your activity [start Activity]
.This code should be contained in your activity so that you can extract the proper keyhash when your signed apk's Activity starts.
private void getHashKey() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("MY_KEY_HASH:",
Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
} }
Your AndroidManifest.xml
file should have the attribute android:allowBackup="true"
in its application tag.
Export your signed apk and Install the app in your mobile phone and then connect your phone in debugging mode with usb debugging on
.
Then go to sdk\platform-tools
Open command prompt and type adb devices
to see whether your device is connected or not. if device not listed then try to fix that issue before continuing to next step.
Then type adb logcat >"log.txt"
. Your cmd
screen will like hanged.
Dont Panic. Its Perfectly normal as the whole logcat is being written to log.txt
.
Run your app and hopefully when you think that the getHashKey()
function is executed then press ctrl+c
on command prompt to end log file writing.
Now the command prompt will become responsive again. Now go into
your sdk\platform-tools
dir and you will see that a log.txt file
has been created which contains logs.
Now open it in a texteditor
and search for MY_KEY_HASH:
"-----------Your keyhash-------"
FB account
or whereever you need it and then make another build in which the android:allowBackup="false"
and getHashKey()
function is
removed.Hope this helped everyone :)