How to create a release signed apk file using Gradle?

前端 未结 30 1699
既然无缘
既然无缘 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条回答
  •  Happy的楠姐
    2020-11-22 14:03

    If you build apk via command line like me then you can provide signing configuration as arguments.

    Add this to your build.gradle

    def getStore = { ->
        def result = project.hasProperty('storeFile') ? storeFile : "null"
        return result
    }
    
    def getStorePassword = { ->
        def result = project.hasProperty('storePassword') ? storePassword : ""
        return result
    }
    
    def getKeyAlias = { ->
        def result = project.hasProperty('keyAlias') ? keyAlias : ""
        return result
    }
    
    def getKeyPassword = { ->
        def result = project.hasProperty('keyPassword') ? keyPassword : ""
        return result
    }
    

    Make your signingConfigs like this

    signingConfigs {
        release {
            storeFile file(getStore())
            storePassword getStorePassword()
            keyAlias getKeyAlias()
            keyPassword getKeyPassword()
        }
    }
    

    Then you execute gradlew like this

    ./gradlew assembleRelease -PstoreFile="keystore.jks" -PstorePassword="password" -PkeyAlias="alias" -PkeyPassword="password"
    

提交回复
热议问题