How can I create a keystore?

后端 未结 11 1095
北恋
北恋 2020-11-22 13:47

What are the steps to create a keystore for android?

I need to use google maps in my app and I don\'t know what steps I missed. Please provide me with the specific d

相关标签:
11条回答
  • 2020-11-22 14:01

    If you don't want to or can't use Android Studio, you can use the create-android-keystore NPM tool:

    $ create-android-keystore quick
    

    Which results in a newly generated keystore in the current directory.

    More info: https://www.npmjs.com/package/create-android-keystore

    0 讨论(0)
  • 2020-11-22 14:04

    This tutorial:

    http://techdroid.kbeanie.com/2010/02/sign-your-android-applications-for.html

    was very helpful for me the first time I had to create a keystore. It is simple but the instructions on developer.android.com are a little too brief.

    The part I was unsure about was where to save and what name to give the keystore file.

    I seems it doesn't matter where you put it just be sure to keep it safe and keep a number of backups. I just put it in my app directory

    Name the file "something.keystore" where something can be whatever you want. I used app_name.keystore, where app_name was the name of my app.

    The next part was what to name the alias. Again it doesn't seem to matter so again I just used the app_name again. Keep the passwords the same as you used before. Fill out the rest of the fields and you are done.

    0 讨论(0)
  • 2020-11-22 14:05

    I'd like to suggest automatic way with gradle only

    ** Define also at least one additional param for keystore in last command e.g. country '-dname', 'c=RU' **

    apply plugin: 'com.android.application'
    
    // define here sign properties
    def sPassword = 'storePassword_here'
    def kAlias = 'keyAlias_here'
    def kPassword = 'keyPassword_here'
    
    android {
        ...
        signingConfigs {
            release {
                storeFile file("keystore/release.jks")
                storePassword sPassword
                keyAlias kAlias
                keyPassword kPassword
            }
        }
        buildTypes {
            debug {
                signingConfig signingConfigs.release
            }
            release {
                shrinkResources true
                minifyEnabled true
                useProguard true
                signingConfig signingConfigs.release
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        ...
    }
    
    ...
    
    task generateKeystore() {
        exec {
            workingDir projectDir
            commandLine 'mkdir', '-p', 'keystore'
        }
        exec {
            workingDir projectDir
            commandLine 'rm', '-f', 'keystore/release.jks'
        }
        exec {
            workingDir projectDir
            commandLine 'keytool', '-genkey', '-noprompt', '-keystore', 'keystore/release.jks',
                '-alias', kAlias, '-storepass', sPassword, '-keypass', kPassword, '-dname', 'c=RU',
                '-keyalg', 'RSA', '-keysize', '2048', '-validity', '10000'
        }
    }
    
    project.afterEvaluate {
        preBuild.dependsOn generateKeystore
    }
    

    This will generate keystore on project sync and build

    > Task :app:generateKeystore UP-TO-DATE
    > Task :app:preBuild UP-TO-DATE
    
    0 讨论(0)
  • 2020-11-22 14:14

    I was crazy looking how to generate a .keystore using in the shell a single line command, so I could run it from another application. This is the way:

    echo y | keytool -genkeypair -dname "cn=Mark Jones, ou=JavaSoft, o=Sun, c=US" -alias business -keypass kpi135 -keystore /working/android.keystore -storepass ab987c -validity 20000
    
    • dname is a unique identifier for the application in the .keystore

      • cn the full name of the person or organization that generates the .keystore
      • ou Organizational Unit that creates the project, its a subdivision of the Organization that creates it. Ex. android.google.com
      • o Organization owner of the whole project. Its a higher scope than ou. Ex.: google.com
      • c The country short code. Ex: For United States is "US"
    • alias Identifier of the app as an single entity inside the .keystore (it can have many)

    • keypass Password for protecting that specific alias.
    • keystore Path where the .keystore file shall be created (the standard extension is actually .ks)
    • storepass Password for protecting the whole .keystore content.
    • validity Amout of days the app will be valid with this .keystore

    It worked really well for me, it doesnt ask for anything else in the console, just creates the file. For more information see keytool - Key and Certificate Management Tool.

    0 讨论(0)
  • 2020-11-22 14:16

    I followed this guide to create the debug keystore.

    The command is:

    keytool -genkeypair -alias androiddebugkey -keypass android -keystore debug.keystore -storepass android -dname "CN=Android Debug,O=Android,C=US" -validity 9999
    
    0 讨论(0)
  • 2020-11-22 14:19

    To answer the question in the title, you create a keystore with the Java Keytool utility that comes with any standard JDK distribution and can be located at %JAVA_HOME%\bin. On Windows this would usually be C:\Program Files\Java\jre7\bin.

    So on Windows, open a command window and switch to that directory and enter a command like this

    keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
    

    Keytool prompts you to provide passwords for the keystore, provide the Distinguished Name fields and then the password for your key. It then generates the keystore as a file called my-release-key.keystore in the directory you're in. The keystore and key are protected by the passwords you entered. The keystore contains a single key, valid for 10000 days. The alias_name is a name that you — will use later, to refer to this keystore when signing your application.

    For more information about Keytool, see the documentation at: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/keytool.html

    and for more information on signing Android apps go here: http://developer.android.com/tools/publishing/app-signing.html

    0 讨论(0)
提交回复
热议问题