How to create a release signed apk file using Gradle?

前端 未结 30 1809
既然无缘
既然无缘 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 14:10

    For Kotlin Script (build.gradle.kts)

    You should not put your signing credentials directly in the build.gradle.kts file. Instead the credentials should come from a file not under version control.

    Put a file signing.properties where the module specific build.gradle.kts is found. Don't forget to add it to your .gitignore file!

    signing.properties

    storeFilePath=/home/willi/example.keystore
    storePassword=secret
    keyPassword=secret
    keyAlias=myReleaseSigningKey
    

    build.gradle.kts

    android {
        // ...
        signingConfigs {
            create("release") {
                val properties = Properties().apply {
                    load(File("signing.properties").reader())
                }
                storeFile = File(properties.getProperty("storeFilePath"))
                storePassword = properties.getProperty("storePassword")
                keyPassword = properties.getProperty("keyPassword")
                keyAlias = "release"
            }
        }
    
        buildTypes {
            getByName("release") {
                signingConfig = signingConfigs.getByName("release")
                // ...
            }
        }
    }
    

提交回复
热议问题