{"id":413,"date":"2016-08-25T14:15:22","date_gmt":"2016-08-25T12:15:22","guid":{"rendered":"http:\/\/davikingcode.com\/blog\/?p=413"},"modified":"2016-08-25T14:20:51","modified_gmt":"2016-08-25T12:20:51","slug":"unity-auto-set-android-password-in-project","status":"publish","type":"post","link":"https:\/\/davikingcode.com\/blog\/unity-auto-set-android-password-in-project\/","title":{"rendered":"Unity &#8211; auto set Android password in project"},"content":{"rendered":"<p>Hey, it&#8217;s time for an other tip today!<\/p>\n<p>There are small details in Unity which can make you crazy: compiling an Android project with the correct certificate request you to provide the password each time you open the project. Ok, that&#8217;s not a big deal! But the problem is: if you miss to write it and launch the compilation it will be at the end of the process than you will be informed you didn&#8217;t set it up and so it fails. With a 30 minute build time (on a big project), if you miss it, you&#8217;ve the right to be angry! Why the hell Unity doesn&#8217;t check it before!?<\/p>\n<p>Anyway let&#8217;s make a small <a href=\"https:\/\/docs.unity3d.com\/Manual\/ExtendingTheEditor.html\" target=\"_blank\">Editor Script<\/a>:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing UnityEngine;\r\nusing UnityEditor;\r\n\r\n[InitializeOnLoad]\r\npublic class StartUp {\r\n\r\n\t#if UNITY_EDITOR\r\n\r\n\tstatic StartUp() {\r\n\r\n\t\tPlayerSettings.keystorePass = &quot;myPwd&quot;;\r\n\t\tPlayerSettings.keyaliasPass = &quot;myAliasPwd&quot;;\r\n\t}\r\n\r\n\t#endif\r\n}\r\n<\/pre>\n<p>Thanks to this script, when the project will be opened the password will be registered!<\/p>\n<p>Ok an other thing to figure, the keystore path is saved in your <em>ProjectSettings.asset<\/em>. So the path need to be changed on each computer. Not a big deal, but it could be done automatically if it&#8217;s near your project. On the script above, add:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nPlayerSettings.Android.keystoreName = Application.dataPath + &quot;\/user.keystore&quot;;\r\n<\/pre>\n<p>The last thing to do would be to reset this path when Unity goes in the background so you can git push\/pull without creating conflict. Unfortunately I can&#8217;t find a way to detect correctly when Unity goes in background, see <a href=\"http:\/\/forum.unity3d.com\/threads\/trapping-if-unity-editor-is-foreground.271391\/\" target=\"_blank\">http:\/\/forum.unity3d.com\/threads\/trapping-if-unity-editor-is-foreground.271391\/<\/a>. Do you know a way to do it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, it&#8217;s time for an other tip today! There are small details in Unity which can make you crazy: compiling an Android project with the correct certificate request you to provide the password each time you open the project. Ok, that&#8217;s not a big deal! But the problem is: if you miss to write it &hellip; <a href=\"https:\/\/davikingcode.com\/blog\/unity-auto-set-android-password-in-project\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Unity &#8211; auto set Android password in project<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_discordance_state":"","_discordance_checked":true},"categories":[15],"tags":[5],"_links":{"self":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/413"}],"collection":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":3,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}