Help us understand the problem. What is going on with this article?

UnityでAndroidのKeystoreパスワードを自動セーブ・ロードする

前提

  • unity 2018.4.7f1
  • Android

できること

  • 一度、KeystoreとAliasのパスワードを設定してビルドすると、以降、エディター起動時に自動的に設定されるようになります。

やりかた

  • 以下のコードを、適当なAssets/~/Editor/~へ入れてください。
SaveKeystore.cs
using UnityEditor;
using UnityEditor.Callbacks;

public class SaveKeystore {

    private static string keystorePrefsName => PlayerSettings.Android.keystoreName;
    private static string keyaliasPrefsName => $"{PlayerSettings.Android.keystoreName}/{PlayerSettings.Android.keyaliasName}";

    [InitializeOnLoadMethod]
    private static void OnLoad () {
        if (string.IsNullOrEmpty (PlayerSettings.Android.keystorePass) && !string.IsNullOrEmpty (PlayerSettings.Android.keystoreName)) {
            PlayerSettings.Android.keystorePass = EditorPrefs.GetString (keystorePrefsName);
        }
        if (string.IsNullOrEmpty (PlayerSettings.Android.keyaliasPass)) {
            PlayerSettings.Android.keyaliasPass = EditorPrefs.GetString (keyaliasPrefsName);
        }
    }

    [PostProcessBuild]
    private static void OnBuilded (BuildTarget target, string path) {
        if (target == BuildTarget.Android) {
            if (!string.IsNullOrEmpty (PlayerSettings.Android.keystoreName) && !string.IsNullOrEmpty (PlayerSettings.Android.keystorePass)) {
                EditorPrefs.SetString (keystorePrefsName, PlayerSettings.Android.keystorePass);
            }
            if (!string.IsNullOrEmpty (PlayerSettings.Android.keyaliasName) && !string.IsNullOrEmpty (PlayerSettings.Android.keyaliasPass)) {
                EditorPrefs.SetString (keyaliasPrefsName, PlayerSettings.Android.keyaliasPass);
            }
        }
    }

}

留意事項

  • KeystoreおよびAliasのパスワードが、平文でエディターの設定内(EditorPrefs)に保存されます。
  • Keystoreファイルの絶対パスに依存します。プロジェクトフォルダを移動するとオートロードできなくなります。
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away