Search code examples
androidandroid-gradle-pluginapkbuild.gradleandroid-productflavors

Generate APK's with different keystores


I've created project with different flavors. Each flavor has it's own application id and it's keystore and password.

On gradle file, I added the signingConfigs section to set the keyAlias, keyPassword, storeFile and storePassword.

Next, on release section in buildTypes, I set the signing config for each flavor.

then, I generated all the flavors. I got all the apk's with the correct content and package names.. but when I tried to upload to play store, I got an error:

Upload failed: You uploaded an APK that is not signed with the upload certificate. 
               You must use same certificate.
               The uploaded certificate has fingerprint "A" and the certificate
               used to sign the APK you uploaded have fingerprint "B".

Now, I understand that it used different certificates.. my question is how can I fix it from gradle? So the generating process of the APK's will also distinguish between the different certificate and will use the correct certificate for each flavor?

The gradle file looks like:

android{

    signingConfigs {
        flavorA {
            keyAlias flavorAKeystoreProperties['keyAlias']
            keyPassword flavorAKeystoreProperties['keyPassword']
            storeFile file(flavorAKeystoreProperties['storeFile'])
            storePassword flavorAKeystoreProperties['storePassword']
        }

        flavorB {
            keyAlias flavorBKeystoreProperties['keyAlias']
            keyPassword flavorBKeystoreProperties['keyPassword']
            storeFile file(flavorBKeystoreProperties['storeFile'])
            storePassword flavorBKeystoreProperties['storePassword']
        }

        flavorC{
            keyAlias flavorCKeystoreProperties['keyAlias']
            keyPassword flavorCKeystoreProperties['keyPassword']
            storeFile file(flavorCKeystoreProperties['storeFile'])
            storePassword flavorCKeystoreProperties['storePassword']
        }       
    }


    flavorDimensions("default")
    productFlavors{

        flavorA{
            dimension "default"
            applicationId "com.example.flavor.flavorA"
            signingConfig signingConfigs.flavorAConfig
        }

        flavorB{
            dimension "default"
            applicationId "com.example.flavor.flavorB"
            signingConfig signingConfigs.flavorBConfig
        }

        flavorC{
            dimension "default"
            applicationId "com.example.flavor.flavorC"
            signingConfig signingConfigs.flavorCConfig
        }
    }   

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            productFlavors.flavorA.signingConfig signingConfigs.flavorAConfig
            productFlavors.flavorB.signingConfig signingConfigs.flavorBConfig
            productFlavors.flavorC.signingConfig signingConfigs.flavorCConfig

    }
        debug {
            applicationIdSuffix ".debug"
            minifyEnabled false
        }
    }
}

Solution

  • For anyone who has the same problem. please check that you typed correctly the flavors names, both in gradle and properties files. also in properties files, check the path for the keystore files and the passwords.