Android风格签名无法正常工作

我需要使用特定的签名配置对产品风味进行签名。我在stackoverflow上找到了一些参考,例如thisthis。它适用于我的flavor发布版本,但不适用于调试版本。我在gradle中有此配置:

...
signingConfigs {
    release {
        storeFile file("../config/keystores/release_keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    debug {
        storeFile file("../config/keystores/debug.keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    other {
        storeFile file("../config/keystores/other")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }
}

flavorDimensions "dim"

productflavors {
    production {
        dimension "dim"
    }

    other {
        dimension "dim"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'        
        productflavors.other.signingConfig signingConfigs.other
        productflavors.production.signingConfig signingConfigs.release
    }

    debug {
        productflavors.other.signingConfig signingConfigs.other
        productflavors.production.signingConfig signingConfigs.debug
    }
}

这对于otherRelease风格来说效果很好。但是,当我使用构建配置other时,我的APK却没有otherDebug签名配置。 release版本已正确签名。

有人知道为什么在调试模式下签名配置未按配置应用吗?

ituyuan 回答:Android风格签名无法正常工作

由于@AllanHasegawa在另一期杂志Signing product flavors with gradle中的评论,我终于弄清了问题所在。简而言之,我必须在signingConfig null内添加buildTypes,因为Android添加了一些默认的签名配置。即使我试图覆盖它。根据我的问题的完整示例:

...
signingConfigs {
    release {
        storeFile file("../config/keystores/release_keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    debug {
        storeFile file("../config/keystores/debug.keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    other {
        storeFile file("../config/keystores/other")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }
}

flavorDimensions "dim"

productFlavors {
    production {
        dimension "dim"
    }

    other {
        dimension "dim"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

        // this loop is a better implementation than my previous example
        productFlavors.all { flavor ->
                flavor.signingConfig signingConfigs.release
        }        
        productFlavors.other.signingConfig signingConfigs.other
    }

    debug {
        signingConfig null
        // this loop is a better implementation than my previous example
        productFlavors.all { flavor ->
                flavor.signingConfig signingConfigs.debug
        }
        productFlavors.other.signingConfig signingConfigs.other
    }
}
本文链接:https://www.f2er.com/2885171.html

大家都在问