App with two flavors generate the same key hash - android

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

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

Related

How to install two separate versions of an app from android studio?

I am working with the Firebase chat project from github.
I am trying to make 2 apps, one client-side and one admin-side.
I have two copies of the project with different project names and different app names.
Still, I can't run both on the same device with android studio. Running one requires uninstalling the other.
I understand it might be a pretty basic thing, but any suggestions?
Thanks
what you need to do is change package name on App Build.Gradle, find applicationId and change one of your project package name
hopefully it works
In your app level build.gradle file under android tag define different product flavors for different app.
Please find the below code and do changes according to your project.
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
flavorDimensions "default"
project.archivesBaseName = "Visualogyx";
signingConfigs {
release {
storeFile file(System.getenv('KEYSTOREPATH'))
storePassword System.getenv("VISUALOGYX_KEYSTORE_PASSWORD")
keyAlias System.getenv("VISUALOGYX_KEYALIAS_NAME")
keyPassword System.getenv("VISUALOGYX_KEYALIAS_PASSWORD")
}
}
defaultConfig {
applicationId "com.visualogyx.app"
minSdkVersion 16
targetSdkVersion 26
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
signingConfig signingConfigs.release
ndk {
abiFilters "armeabi-v7a"
}
}
lintOptions {
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
dexOptions {
javaMaxHeapSize "4g"
jumboMode true
}
productFlavors {
dev {
versionCode 778899
versionName "v.1.1.BUILD_NUM"
applicationIdSuffix ".dev"
resValue "string", "app_name", "VisualogyxDEV"
buildConfigField "String", "HOST", System.getenv("VISUALOGYX_HOST_DEV")
}
qa {
versionCode 778899
versionName "v.1.0.BUILD_NUM"
applicationIdSuffix ".qa"
resValue "string", "app_name", "VisualogyxQA"
buildConfigField "String", "HOST", System.getenv("VISUALOGYX_HOST_QA")
}
pro {
versionCode 778899
versionName "v.1.0.BUILD_NUM"
resValue "string", "app_name", "Visualogyx"
buildConfigField "String", "HOST", System.getenv("VISUALOGYX_HOST_PRO")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "Visualogyx-${variant.baseName}-${variant.versionName}.apk"
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/XXX'
}
}
Hope it works.Thanks.

Why doesn't Firebase display events issued by my app?

I built an app and registered it with Firebase as part of a project that includes three other apps. Here's what my buildTypes in the app gradle build file looks like:
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "RULE_DEBUG_LEVEL", "0"
}
releaseDebuggable {
debuggable true
buildConfigField "int", "RULE_DEBUG_LEVEL", "1"
}
debug {
//applicationIdSuffix '.debug'
versionNameSuffix " Debug"
buildConfigField "int", "RULE_DEBUG_LEVEL", "1"
}
and the productFlavors are as follows:
flavorDimensions "fmplus"
productFlavors {
String name = "fmplus"
fmplus {
name = "fmplus"
applicationId getPackageName(name)
resValue 'string', 'app_name', getAppName(name)
resValue 'color', 'accent', getThemeColor(name)
resValue 'color', 'accentDark', getThemeColorDark(name)
}
fmplus_nab_htc_one_m8 {
name = "fmplus"
applicationId getPackageName(name)
applicationIdSuffix ".nab_htc_one_m8"
versionNameSuffix "-nab_htc_one_m8"
resValue 'string', 'app_name', getAppName(name)
resValue 'color', 'accent', getThemeColor(name)
resValue 'color', 'accentDark', getThemeColorDark(name)
}
fmplus_nyx_supraim_sn10 {
name = "fmplus"
applicationId getPackageName(name)
applicationIdSuffix ".nyx_supraim_sn10"
versionNameSuffix "-nyx-supraim-sn10"
resValue 'string', 'app_name', getAppName(name)
resValue 'color', 'accent', getThemeColor(name)
resValue 'color', 'accentDark', getThemeColorDark(name)
}
changeFileManifest(name)
}
Another programmer on our team handled the flavor labelled 'fmplus_nyx_supraim_sn10' and I'm doing 'fmplus_nab_htc_one_m8'. Both apps appear in Firebase under the same project, but Firebase reports his events but not mine. I've been struggling with this for some time now and have run out of ideas. Does anyone have an idea what I'm doing wrong. And yes, I downloaded and installed the google-services.json file and rebuilt the app before running it, just like the docs say.
The problem was in the app gradle file: Android Studio 3.0 requires a default dimensions statement, which I have, but what I also needed to do was add a dimension statement to the build flavor in question. The other developer, whose app didn't have this problem, was using Studio 2.3.3.

Android testing release build

I tried to test the release build of the app. So I have added the below config to build.gradle of my app. But that didn't make any effect. Test always runs on debug build
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.****.****"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0 Beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
testBuildType "release"
signingConfigs {
release {
keyAlias '******'
keyPassword '*****'
storeFile file('path to keystore')
storePassword '*****'
}
}
buildTypes {
release {
minifyEnabled true
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
multiDexEnabled true
}
}
}
When searched for answers in other SO thread I found testBuildType "release" will run test on release build but it did not work
I'm not sure I got it all, but a few things :
You can test your release with the build variant menu on Android studio (menu at the bottom left) (#Sagar Chavada suggestion)
When you generate your signed apk with Android studio you can choose at the end the build type, release in your case
I know it's for testing purpose but debuggable true in your realease build won't allow you to push it on Google play
Whenever you are building a project and want to create a signed apk then
Add following code in to android {} in your build.gradle file.
productFlavors {
RELEASE {
applicationIdSuffix ".release"
versionNameSuffix "-release"
}
DEBUG {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
}
}
Go to Android SDK --> Build.
Tap on Generate Signed APK
It will ask to create a debug or Signed build (apk format)
Then select release flavour and generate apk.

why do i have to sign qa flavor in gradle?

i have this build config in my gradle file ?
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
applicationIdSuffix ".debug"
versionNameSuffix ".debug"
}
qa {
applicationIdSuffix ".qa"
versionNameSuffix ".qa"
}
}
sourceSets { debug { res.srcDirs = ['src/debug/res', 'src/debug/res/values'] } }
}
why when i am try to run qa it trow me and error for not having key for this flavor ?
The only build type for which Gradle can build your project "out of the box" is debug, as the Android Plugin for Gradle knows to use the plugin-created debug signing keystore. For everything else, you either need to:
Configure a separate signing keystore (e.g., for release)
Initialize the new build type from the debug build type, akin to using a copy constructor, so it uses the same rules that debug does for signing
In the following sample, I want to define a new mezzanine build type, giving it the same signing configuration as I use for release. So, I use mezzanine.initWith(buildTypes.release) to set up mezzanine as a copy of release, then continue to configure it with different rules:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
versionCode 2
versionName "1.1"
minSdkVersion 14
targetSdkVersion 18
}
signingConfigs {
release {
storeFile file('HelloConfig.keystore')
keyAlias 'HelloConfig'
storePassword 'laser.yams.heady.testy'
keyPassword 'fw.stabs.steady.wool'
}
}
buildTypes {
debug {
applicationIdSuffix ".d"
versionNameSuffix "-debug"
}
release {
signingConfig signingConfigs.release
}
mezzanine.initWith(buildTypes.release)
mezzanine {
applicationIdSuffix ".mezz"
debuggable true
}
}
}
In your case, you would use something like qa.initWith(buildTypes.debug) before configuring the rest of the qa build type.

Building Different APK with different flavors

I want to be able to build same app with different package name. My current approach is using flavor (build variant). This works fine except that app built on different flavors replaces the other one on the device. What i want to achieve is building this same app with different flavors and not replacing same app on the same phone built with another flavor. Below is a snippet of my current approach. How can i achieve and am i doing anything wrong?
buildTypes {
release {
applicationIdSuffix ".release"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
}
}
flavorDimensions "flavor"
productFlavors {
flavor1 {
flavorDimension "flavor"
applicationId
"com.eample.flavor1"
versionName "1.0"
}
flavor2 {
flavorDimension "flavor"
applicationId
"com.example.flavor2"
versionName "1.0"
}
flavor3 {
flavorDimension "flavor"
applicationId
"com.example.flavor3 "
versionName "1.0"
}
}

Categories

Resources