Adding release keys in the experimental Gradle plugin for Android

前端 未结 3 1103
天命终不由人
天命终不由人 2021-01-19 21:40

Hey I am having some issues adding a signing my release build variant. Currently I am using the experimental gradle 2.5 with the new android gradle plugin version 0.1.0.

相关标签:
3条回答
  • 2021-01-19 22:21

    This workaround works for me and does not require -Dorg.gradle.model.dsl=true

    model {
        def signConf
    
        android.buildTypes {
            release {
                signingConfig = signConf
            }
        }
    
        android.signingConfigs {
            create("signed") {
                keyAlias = "meow"
                keyPassword = "**"
                storeFile = file("meow-key.keystore")
                storePassword = "**"
                storeType = "jks"
    
                signConf = it
            }
        }
    }
    

    However, it only works if you only have one signingConfig.

    0 讨论(0)
  • 2021-01-19 22:21

    You should be able to add the release keys with a script like this:

    model {
        android.buildTypes {
            release {
                signingConfig = $("android.signingConfigs.signed")
            }
        }
    
        android.signingConfigs {
            create("signed") {
                keyAlias = "meow"
                keyPassword = "**"
                storeFile = file("meow-key.keystore")
                storePassword = "**"
                storeType = "jks"
            }
        }
    }
    

    Currently it seems to be a bug in the plugin.
    You need to specify -Dorg.gradle.model.dsl=true when you run your gradle command.

    Also you should have an issue with proguard. In this case you can use new File("path/to/proguard-rules.pro") instead of file('proguard-rules.pro')

    0 讨论(0)
  • 2021-01-19 22:26

    The right way to do this with the latest version of the Android plugin (0.6.0-alpha3) is as follows:

    android.signingConfigs {
        create("release") {
            storeFile = file("../keys.keystore")
            storePassword = "st0r3pa$$"
            keyAlias = "SecretKey"
            keyPassword = "k3ypa$$"
        }
    }
    
    android.buildTypes {
        release {
            signingConfig = $.android.signingConfigs.get("release")
        }
    }
    

    In Gradle 2.9 which is used by this version of the plugin, the declared rules can depend on each other using a special syntax: $.<path-to-element>. The trick is to create the signing config as usual, then assign it to a field in a different rule using this syntax. Gradle will realize that the signing configuration is an input dependency and will let you access it.

    0 讨论(0)
提交回复
热议问题