Confused with signing android APK?

后端 未结 1 481

I have followed the steps as per officials says for digitally signing my android application.for signing in release mode they are saying to use .keystore file and i

相关标签:
1条回答
  • 2021-01-22 12:50

    You can put the .jks file anywhere.
    It means that you can put the file inside your project, or you can put the file in an external folder (just take a look the path below). It depends by your policy.

    Just use gradle to configure the signing of your apk.

    android {
    
        signingConfigs {
            release
        }
    
        buildTypes {
                release {
                    signingConfig signingConfigs.release
                }
        }
    }
    

    Simple way: just define the credential inside your build.gradle file.

    signingConfigs {
         release {
                //Pay attention to the path. You can use a relative path or an absolute path
                storeFile file("../your_key_store_file.jks")
                storePassword 'some_password'
                keyAlias 'alias_name'
                keyPassword 'key_password'
    
         }
      }
    

    Using a .properties file to store the credentials outside the script (for example if you don't want to push the credential in a git repo).

    Example: signing.properties

    STORE_FILE=/path/to/your.keystore
    STORE_PASSWORD=yourkeystorepass
    KEY_ALIAS=projectkeyalias
    KEY_PASSWORD=keyaliaspassword
    

    Then get these values in your build.gradle file:

    signingConfigs {
            release
     }
    

    Then define:

    def Properties props = new Properties()
    def propFile = new File('signing.properties')
    if (propFile.canRead()){
        props.load(new FileInputStream(propFile))
    
        if (props!=null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
                props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
            android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
            android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
            android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
            android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
        } else {
            println 'signing.properties found but some entries are missing'
            android.buildTypes.release.signingConfig = null
        }
    }else {
        println 'signing.properties not found'
        android.buildTypes.release.signingConfig = null
    }
    
    0 讨论(0)
提交回复
热议问题