Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Android Signing

Discussion in 'Android' started by murali.vvn, Sep 30, 2010.

  1. murali.vvn

    murali.vvn

    Joined:
    Jun 28, 2010
    Posts:
    53
    Is it required to sign our apk file ? If yes how to do it?
     
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    For development : No. For publishing (i.e. Android Market) : Yes.

    1) Locate the Publishing Settings under PlayerSettings
    2) Create a new keystore by selecting a keystore name and password (confirm the password)
    3) Select "Create a new key" under Key Alias
    4) A new window opens; enter the necessary information.
    5) Select the newly created key.
    6) Build ( Run); your app is now signed.

    n.b. Remember the passwords; they are not stored with the project (for security reasons).
     
  3. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    How to save key?

    Can't find saved "user.keystore"
     
  4. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    The keystore (including the key) will be created after step 4 below (ie after entering the details of the key)
     
  5. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    ...
    Having trouble with this - I don't get a new window, and Create New Key is a checkbox above, not a selection under Key Alias. I'm still on f5 build.
     
  6. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    No, it's "Create New _Keystore_" that is a checkbox.

    Did you select "Create New Keystore" (assuming you don't already have one)?
    Did you select a name for the Keystore (Browse Keystore)?
    Did you enter a keystore password?
    Did you confirm it (and does it match)?
    Only then will the "Create New Key" be visible under KeyAlias.

    When pulling down the KeyAlias drop list do you get any errors in the Console log?
     
    Onivas85, piginhat, Dadusak and 5 others like this.
  7. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    ah, thanks Erique - didn't click Browse Keystore and save first.
     
    mikecamimo, orvedal and Symyon like this.
  8. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    FYI, In Windows, I had to download/install JDK and then manually add the JDK bin path to my PATH variable in Windows before I could get KeyTool and JarSigner to work from Unity. JDK installer did not do that automatically.
     
  9. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    The 3.1 release will hopefully remedy this. If possible, please try the 3.1beta as it includes the fix for finding JAVA_HOME if not set by the JDK installer.
     
    Dadusak likes this.
  10. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Sailesh_India likes this.
  11. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    I have the same problem of Akasurreal: Unity does not find the command to create the keystore, so it saves nothing.
    I'm trying to follow his procedure and see if it works.
    I am on W7-64b.
     
  12. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    You need to either install the JDK (on Windows usually), or have the jarsigner command in the PATH (which is the normal case for OSX).
     
    dev_alleylabs likes this.
  13. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    I added JAVA_HOME variable with value C:\Program Files\Java\jre6\
    Now I'm restarting the computer :D
     
  14. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    That probably won't do; you need the JDK, not the JRE.
     
  15. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    I downloaded the JDK, what the hell?

    OK it works with value = C:\Program Files\Java\jdk1.6.0_23 :D

    Without the :D at the end!
     
    Last edited: Dec 17, 2010
  16. AdsySingle

    AdsySingle

    Joined:
    Jan 5, 2011
    Posts:
    116
    I can't get this to work. I have my JDK installed at C:/Program Files/Java/jdk1.6.0_24 and I have made a PATH environment variable with this path. No matter what I do Unity tells me Unable to run keytool; do you have the JDK installed?
     
  17. gamestudio

    gamestudio

    Joined:
    Mar 10, 2010
    Posts:
    27
    Hi, my java sdk version is 1.6.0_23

    1 ::.

    $publish1.jpg

    2 ::.

    $publish2.jpg

    3 ::.

    - Please read this URL -> http://www.devdaily.com/java/java-using-keytool-genkey-private-key-keystore
    http://www.devdaily.com/java/java-using-keytool-list-query

    - Goto start button and key cmd command at Run...
    - Use this command for create privateKey.store file ::.
    keytool -genkey -alias foo -keystore privateKey.store
    - Use this command for view your first alias name
    keytool -list -v -keystore privateKey.store

    4 ::. Publishing Setting

    - Check at Create New Keystore
    - Insert your keystore password first
    - Comfirm your keystore password again​
    - Check Existing Keystore
    - Press Browse Keystore button
    - Select file privateKey.store
    - Now you can see foo at Alias name combo box already
    - You can create new Key by unity3d

    $publish4.jpg

    $publish5.jpg
    5 :: Please try and Good luck.
     
    Last edited: Apr 8, 2011
  18. WolfoX

    WolfoX

    Guest


    Use JDK 6u14 (jdk1.6.0_14). Unity works fine with that version.
    If you live outside USA, just rollback to 6u14 and it will work.
     
  19. tektor

    tektor

    Joined:
    Nov 16, 2010
    Posts:
    7
    Anyone know how to sign an APK when building from the command-line (e.g. from a build script or CI server)? Looks like the keystore/key passwords aren't saved, so can BuildPipeline.BuildPlayer() be used to build non-debug signed APKs?
     
  20. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
  21. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    the password for the alias, does it need to be the same as that of the keystore?
     
  22. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    No; you can set separate passwords for each keyalias inside a keystore.
     
  23. deepak

    deepak

    Joined:
    Aug 10, 2010
    Posts:
    44
    If i had lost the keystore and want to update the version in android market. Is there a solution for this?
     
  24. danilonishimura

    danilonishimura

    Joined:
    Jul 13, 2010
    Posts:
    70
  25. ailtonguitar

    ailtonguitar

    Joined:
    May 19, 2011
    Posts:
    1
    Hi, I did all the procedure described in the posts but my alias not shown in the Key Alias combobox . What can I do?
     
  26. jmpp

    jmpp

    Joined:
    Jun 1, 2010
    Posts:
    93

    Hi erique! Long since you posted these instructions, but I still have a question regarding the Google recommended procedure to publish Android apps. I could jump into Terminal (I'm on a Mac) to do the entire process there, but it'd be great to learn to do it in Unity too. I already have my keystore key and necessary utilities configured in my path, and in reading the docs at http://developer.android.com/guide/publishing/app-signing.html I see a step that you didn't address, which is optimizing the signed apk with zipalign. When you configure Unity properly for Android publishing and hit Build, is it still necessary to manually align the apk or does Unity take care of that for you too?

    Cheers!


    - jmpp
     
  27. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    +1 !!!

    please answer to this question !
     
  28. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    We take care of all that to make sure the .apk is ready to be uploaded to the Android Market (or similar). The .apk is signed and aligned the same way as when using Eclipse or ANT. It is not necessary to align the .apk manually.
     
    Symyon likes this.
  29. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    erique thanks !
     
  30. jmpp

    jmpp

    Joined:
    Jun 1, 2010
    Posts:
    93
    Thanks for the confirmation erique! So sweet to have a one-click-to-publish solution all within Unity, kudos!

    Regards,


    - jmpp
     
  31. BeforeTheLight

    BeforeTheLight

    Joined:
    Jan 7, 2011
    Posts:
    168
    Ok I have a keystore and alias setup No errors. select use keystore enter Pw, select my alias enter pw. My passwords are correct!! Build and run and get errors.
    Unable to install APK!
    pkg: /data/local/tmp/Package.apk

    Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

    1719 KB/s (6446484 bytes in 3.661s)

    UnityEngine.Debug:LogError(Object)
    PostProcessAndroidPlayer:UploadAndStartPlayer(String, String, String, String, String, Boolean, Single, Single, Boolean) (at C:/BuildAgent/work/842f9557127e852/Editor/Mono/BuildPipeline/PostProcessAndroidPlayer.cs:826)
    PostProcessAndroidPlayer:postProcess(BuildTarget, String, String, String, String, String, String, BuildOptions) (at C:/BuildAgent/work/842f9557127e852/Editor/Mono/BuildPipeline/PostProcessAndroidPlayer.cs:403)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

    Should it build and run?

    Where should the keystore file be saved? Anywhere? Or in the project folder somewhere?

    If I just Build it builds to a .apk just fine. Try to upload to android market Devolper console and get "An unexpected error occurred. Please try again later." and thats it no more information. Waited a day and got the same and another day and the same now four days later same issue. Any help is good help Thank You in advance!!
     
    Last edited: Sep 24, 2011
  32. BeforeTheLight

    BeforeTheLight

    Joined:
    Jan 7, 2011
    Posts:
    168
    To answer my own question uninstall jdk 1.7.0 and install 1.6.23 and all better. Found the answer in unity answers. Thanks.
     
  33. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    122
    I am so frustrated right now .... I just downloaded the new JDK and this is not working.... by the way is the country code for the United States 01, that's my best guess after googling us country code.
    trying to install the JDK 6u14 (jdk1.6.0_14) like WolfoX suggested... hope this works
     
  34. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    122
    BeforeTheLight, can you provide a link to the JDK version you downloaded?
     
  35. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    122
    Unable to run 'keytool'; do you have the JDK installed?
    System.ComponentModel.Win32Exception: ApplicationName='keytool.exe', CommandLine='-genkey -keystore "C:/Users/David/user.keystore" -storepass zipzap01 -alias earthcrosser -keypass zipzap01 -validity 18250 -dname "CN=David Robinson, OU=earthcrosser, O=Earth Crossers, L=Arlington, S=VA, C=01"', CurrentDirectory=''
    at System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0
    at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0
    at System.Diagnostics.Process.Start () [0x00000] in <filename unknown>:0
    at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
    at UnityEditor.Utils.Program.Start () [0x00033] in C:\BuildAgent\work\842f9557127e852\Editor\Mono\Utils\Program.cs:30
    at UnityEditor.AndroidKeystoreWindow.CreateKey (System.String keystore, System.String storepass) [0x001ea] in C:\BuildAgent\work\842f9557127e852\Editor\Mono\GUI\AndroidKeystoreWindow.cs:321
    UnityEditor.HostView:OnGUI()


    HELP
     
  36. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    122
    I tried all this stuff and I'm still having no luck
     
  37. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    122
    Turns out I just needed to use the 32 bit JDK not the 64 bit JDK, so that fixed it
     
  38. Daniel FF

    Daniel FF

    Joined:
    Mar 23, 2009
    Posts:
    70
    Yeah, always our annoying friend Java. The mister independent plataform where independent pltaform means bad and slow independently of the platform. Why they dont wanna let that weird thing die ? and I would love to say RIP Java.
    God bless Microsoft and Apple with your native,stable and fast code.

    Sorry for this mad post, but I'm very tired.
     
  39. Argenex

    Argenex

    Joined:
    Jan 7, 2011
    Posts:
    34
    Wow, so I am having the same problems that everyone else has had here.

    Ok so adding the location of the installation to the system environment variables
    for Windows Business Vista 64x with a jdk1.7.0_01 version install
    fixed the issues I was having.
     
    Last edited: Nov 23, 2011
  40. Surreal

    Surreal

    Joined:
    Dec 10, 2011
    Posts:
    29
    I'm having a variant of this issue -- I have Windows 7 64 bit, and jdk 1.7.

    Everything gets signed just fine through Unity. But when I deploy to the Android Market -- or install through a manual download -- the install fails -- I get the message Application Not Installed. From the market I get a signature error

    When I look at the APK using jarsigner verify, I get this message:

    [CertPath not validated: Path does not chain with any of the trust anchors]

    Any help is appreciated.
     
    Last edited: Dec 10, 2011
  41. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    I wasnt able to figure out how to create a keygen using unity but its easy enough if you just use the command line.
     
  42. Whiplash

    Whiplash

    Joined:
    Dec 14, 2011
    Posts:
    6
    I have the same issue as Adsy, where as when I try to make the new key, the following error pops up in the console: "Unable to run keytool; do you have the JDK installed?"

    I do have the JDK installed, but unity doesn't seem to find it. I found the keytool.exe, but unity won't listen when I try to redirect it there.
    Any help would be greatly appreciated. :)
     
  43. ianismrt

    ianismrt

    Joined:
    Mar 1, 2012
    Posts:
    3
    Also anyone coming here having KeyStore issues with Windows 7, make sure that you install the 32bit version of JDK. the 64bit version will not work
     
  44. simom85

    simom85

    Joined:
    May 27, 2010
    Posts:
    283
    you can create it whit this:

    keytool -genkey -keystore xxxx.keystore -storepass xxxxxx -alias xxx -validity 18250 -dname "CN=xxx, OU=xxx, O=xxxxxxx xxxxxx"
     
  45. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    I got a keystore from an external party to sign my android build with and the name of the key i need to sign with contains a space. So i'm getting an error saying that it can't find a key with that name. Where that name is the first part before the space only. Is there a way to have the build process recognize the whole name of the key?
     
  46. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Currently no - I've just fixed this problem, but it will take some time to get the fix through testing and be released to the world.

    As a workaround you can sign the .apk on the command line using

    Code (csharp):
    1. $ jarsigner -verbose -sigalg <sigalgo, probably MD5withRSA> -digestalg SHA1 -keystore file.keystore app.apk keyname
    (as described here : http://developer.android.com/guide/publishing/app-signing.html)

    Just make sure you remove any debug certificates first, i.e.

    Code (csharp):
    1. $ zip -d app.apk "META-INF*"
     
  47. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Thank you Enrique.
    Yes, i did sign and align the apk manually as a temporary workaround. No big deal, just takes 2 min longer. :)
     
  48. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    134
    Has anyone had a problem when uploading a new version of an existing app, signed with the old and same keystore where the Dev console spits out an error:
    "The apk must be signed with the same certificates as the previous version."

    Now, i opened up my old source which i haven't touched for about 4 months, fixed a few bugs and made a new build. It was still referencing the old keystore in the playerSettings, so i'm definitely using the same key...

    Is it possible to just delete the current APK (v1.0) in the dev console, and upload a new one with the keystore im currently signing with?
     
  49. francksitbon

    francksitbon

    Joined:
    Jan 22, 2010
    Posts:
    268
    Hi about this key, does it allow a copy protection?

    Should I choose in the publish page, copy protection unable or disable?

    It says that this option will disappear and be changed with app licensing. Is it included in unity build?
     
  50. androosha

    androosha

    Joined:
    Nov 30, 2011
    Posts:
    7
    I have a trouble.
    After updating Unity up to 3.5.3 (free Unity + iOS license + Android license) I can't to sign my apk applications. And in the previous unity version signing with same keystore works with no problems.
    What is this? How to solve this problem?