diff --git a/Facebook.Unity.Editor/FacebookSettingsEditor.cs b/Facebook.Unity.Editor/FacebookSettingsEditor.cs index 9f110994..c9bb5699 100644 --- a/Facebook.Unity.Editor/FacebookSettingsEditor.cs +++ b/Facebook.Unity.Editor/FacebookSettingsEditor.cs @@ -62,6 +62,7 @@ public class FacebookSettingsEditor : Editor private GUIContent packageNameLabel = new GUIContent("Package Name [?]", "aka: the bundle identifier"); private GUIContent classNameLabel = new GUIContent("Class Name [?]", "aka: the activity name"); private GUIContent debugAndroidKeyLabel = new GUIContent("Debug Android Key Hash [?]", "Copy this key to the Facebook Settings in order to test a Facebook Android app"); + private GUIContent editorAndroidKeyLabel = new GUIContent("Editor Android Key Hash [?]", "Copy this key to the Facebook Settings in order to test a Facebook Android app"); private GUIContent autoLogAppEventsLabel = new GUIContent("Auto Logging App Events [?]", "If true, automatically log app install, app launch and in-app purchase events to Facebook. https://developers.facebook.com/docs/app-events/"); private GUIContent advertiserIDCollectionLabel = new GUIContent("AdvertiserID Collection [?]", "If true, attempts to collect user's AdvertiserID. https://developers.facebook.com/docs/app-ads/targeting/mobile-advertiser-ids/"); @@ -313,6 +314,7 @@ private void AndroidUtilGUI() this.SelectableLabelField(this.packageNameLabel, Utility.GetApplicationIdentifier()); this.SelectableLabelField(this.classNameLabel, ManifestMod.DeepLinkingActivityName); this.SelectableLabelField(this.debugAndroidKeyLabel, FacebookAndroidUtil.DebugKeyHash); + this.SelectableLabelField(this.editorAndroidKeyLabel, FacebookAndroidUtil.CurrentKeyHash); if (GUILayout.Button("Regenerate Android Manifest")) { ManifestMod.GenerateManifest(); diff --git a/Facebook.Unity.Editor/android/FacebookAndroidUtil.cs b/Facebook.Unity.Editor/android/FacebookAndroidUtil.cs index cc9ee2ea..57fc496a 100644 --- a/Facebook.Unity.Editor/android/FacebookAndroidUtil.cs +++ b/Facebook.Unity.Editor/android/FacebookAndroidUtil.cs @@ -39,6 +39,7 @@ public class FacebookAndroidUtil public const string ErrorKeytoolError = "java_keytool_error"; private static string debugKeyHash; + private static string currentKeyHash; private static string setupError; public static bool SetupProperly @@ -86,6 +87,44 @@ public static string DebugKeyHash } } + public static string CurrentKeyHash + { + get + { + if (currentKeyHash == null) + { + if (!HasAndroidSDK()) + { + return ErrorNoSDK; + } + + if(string.IsNullOrEmpty(PlayerSettings.Android.keystoreName)) + { + return ErrorNoKeystore; + } + + if(string.IsNullOrEmpty(PlayerSettings.Android.keyaliasName)) + { + return ErrorNoKeystore; + } + + if (!DoesCommandExist("echo \"xxx\" | openssl base64")) + { + return ErrorNoOpenSSL; + } + + if (!DoesCommandExist("keytool")) + { + return ErrorNoKeytool; + } + + currentKeyHash = GetKeyHash(PlayerSettings.Android.keyaliasName, PlayerSettings.Android.keystoreName, PlayerSettings.Android.keystorePass, PlayerSettings.Android.keyaliasPass); + } + + return currentKeyHash; + } + } + public static string SetupError { get @@ -145,7 +184,8 @@ public static string GetAndroidSdkPath() return sdkPath; } - private static string GetKeyHash(string alias, string keyStore, string password) + private static string GetKeyHash(string alias, string keyStore, string password) => GetKeyHash(alias,keyStore,password,password); + private static string GetKeyHash(string alias, string keyStore, string keystorePassword, string aliasPassword) { var proc = new Process(); var arguments = @"""keytool -storepass {0} -keypass {1} -exportcert -alias {2} -keystore {3} | openssl sha1 -binary | openssl base64"""; @@ -160,7 +200,7 @@ private static string GetKeyHash(string alias, string keyStore, string password) arguments = @"-c " + arguments; } - proc.StartInfo.Arguments = string.Format(arguments, password, password, alias, keyStore); + proc.StartInfo.Arguments = string.Format(arguments, keystorePassword, aliasPassword, alias, keyStore); proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardOutput = true;