Android flavors signing not working as expected

巧了我就是萌 提交于 2020-01-25 08:02:19

问题


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

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?


回答1:


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


来源:https://stackoverflow.com/questions/59426636/android-flavors-signing-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!