How to create a release signed apk file using Gradle?

前端 未结 30 1680
既然无缘
既然无缘 2020-11-22 13:48

I would like to have my Gradle build to create a release signed apk file using Gradle.

I\'m not sure if the code is correct or if I\'m missing a parameter when doing

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 13:58

    Almost all platforms now offer some sort of keyring, so there is no reason to leave clear text passwords around.

    I propose a simple solution that uses the Python Keyring module (mainly the companion console script keyring) and a minimal wrapper around Groovy ['do', 'something'].execute() feature:

    def execOutput= { args ->
        def proc = args.execute()
        proc.waitFor()
        def stdout = proc.in.text
        return stdout.trim()
    }
    

    Using this function, the signingConfigs section becomes:

    signingConfigs {
        release {
            storeFile file("android.keystore")
            storePassword execOutput(["keyring", "get", "google-play", storeFile.name])
            keyAlias "com.example.app"
            keyPassword execOutput(["keyring", "get", "google-play", keyAlias])
        }
    }
    

    Before running gradle assembleRelease you have to set the passwords in your keyring, only once:

    $ keyring set google-play android.keystore # will be prompted for the passwords
    $ keyring set google-play com.example.app
    

    Happy releases!

提交回复
热议问题