Android风格签名无法正常工作 [英] Android flavors signing not working as expected

查看:70
本文介绍了Android风格签名无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to sign a product flavor with an specific signing configuration. I found some reference here at stackoverflow like this and this. It is working for my release version of flavor, but not the debug one. I have this configuration in 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非常有效.但是,当我使用构建配置otherDebug时,我的APK没有被other签名配置所分隔. release版本已正确签名.

This works pretty well for the flavor otherRelease. But my APK is not being sigined with other signing configuration when I use the build configuration otherDebug. The release version was signed correctly.

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

Does anyone knows why in debug mode the signing configuration is not being applied as configured?

推荐答案

由于@AllanHasegawa在另一个问题中的评论,我终于找出了问题所在:

I finally figured out what was wrong, thanks to @AllanHasegawa with his comment in another issue: Signing product flavors with gradle . For short, I had to add signingConfig null inside buildTypes because Android adds some default signing configuration. Even though I was trying to override it. Complete example based on my question:

...
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
    }
}

这篇关于Android风格签名无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆