How to create a release signed apk file using Gradle?

前端 未结 30 1681
既然无缘
既然无缘 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:06

    If you want to avoid hardcoding your keystore & password in build.gradle, you can use a properties file as explained here: HANDLING SIGNING CONFIGS WITH GRADLE

    Basically:

    1) create a myproject.properties file at /home/[username]/.signing with such contents:

    keystore=[path to]\release.keystore
    keystore.password=*********
    keyAlias=***********
    keyPassword=********
    

    2) create a gradle.properties file (perhaps at the root of your project directory) with the contents:

    MyProject.properties=/home/[username]/.signing/myproject.properties
    

    3) refer to it in your build.gradle like this:

        if(project.hasProperty("MyProject.properties")
            && new File(project.property("MyProject.properties")).exists()) {
    
        Properties props = new Properties()
        props.load(new FileInputStream(file(project.property("MyProject.properties"))))
    
        signingConfigs {
            release {
                storeFile file(props['keystore'])
                storePassword props['keystore.password']
                keyAlias props['keyAlias']
                keyPassword props['keyPassword']
            }
        }
    }
    

提交回复
热议问题