Search code examples
androidfacebookcode-signingandroid-keystoreandroid-productflavors

App with two flavors generate the same key hash


I have two apps from the same project with two different flavors, they have Facebook sign-in, one of them is published and working fine, the problem is with the other flavor, every thing is working fine in debug, but when i try to login with facebook in release i got invalid key hash, the key hash doesn't match... I tried re-generating the key hash many times, even with differnt keystore, but i have the same result, I even tried copying the key hash in the error message with no luck. Then I compared the key hash with the published app's key hashes in facebook console, and it was there.

My question is why the two flavors have the same key hashes even they have different package names and facebook ApplicationIds in different manifest files ?

This is my build.gradle

android {
signingConfigs {
    release {
        keyAlias 'alias'
        keyPassword '********'
        storeFile file('keystore.jks')
        storePassword '********'
        v2SigningEnabled false
    }
}
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 25
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}

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

        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
flavorDimensions "app"
productFlavors {
    A {
        dimension "app"
        applicationId "com.app1"
        versionCode 12
        versionName '1.12'
        resValue "string", "app_name", "App1"
        resValue "string", "facebook_app_id", "1**************7"
        resValue "string", "fb_login_protocol_scheme", "fb1**************7"
    }

    B {
        dimension "app"
        applicationId "com.app2"
        versionCode 0
        versionName '1.0'
        resValue "string", "app_name", "App2"
        resValue "string", "facebook_app_id", "1**************5"
        resValue "string", "fb_login_protocol_scheme", "fb1**************5"
    }
}

Solution

  • Your using the same signing configuration for both variants with the same keystore, please different keystore for each variant.