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.
Related
I'm building an Android app with React Native and I have troubles configuring some of my API key.
I have one of my API key in my Gradle.properties
RNGP_ANDROID_API_KEY=mysupersecretkey
And I have two different flavor: beta for testing and prod for production.
I would like to override the RNGP_ANDROID_API_KEY in my two flavors
Like this:
flavorDimensions 'env'
productFlavors {
beta {
dimension 'env'
applicationId "com.fake.package"
signingConfig signingConfigs.release
manifestPlaceholders=[google_api:"beta_key"]
}
prod {
dimension 'env'
applicationId "com.fake.package"
signingConfig signingConfigs.release
manifestPlaceholders=[google_api:"prod_key"]
}
}
It works well to override value in the manifest but I don't know how to change the Gradle.properties value.
Please let me know what I can do!
Instead of writing in Gradle.properties
Try to use it as below,
flavorDimensions 'env'
productFlavors {
beta {
dimension 'env'
applicationId "com.fake.package"
signingConfig signingConfigs.release
manifestPlaceholders=[google_api:"beta_key"]
buildConfigField 'String', 'RNGP_ANDROID_API_KEY', '"mysupersecretkey"'
}
prod {
dimension 'env'
applicationId "com.fake.package"
signingConfig signingConfigs.release
manifestPlaceholders=[google_api:"prod_key"]
buildConfigField 'String', 'RNGP_ANDROID_API_KEY', '"mysupersecretkey"'
}
}
You can access this variable by BuildConfig.RNGP_ANDROID_API_KEY
To install two different instances of the same app is easy. I just use productFlavors.
The problem comes when I install the app from Google Play and try to install another flavor. I can't have an app from Google Play and a flavor one at the same time but two flavors apps yes.
How can I install both apps in the same phone, Google Play app and Flavor app.
PD: I am using different flavors, this is an example of them:
QA {
resValue "string", "app_name", "My app QA"
applicationId "com.myapp.qa"
}
GOOGLEPLAY{
resValue "string", "app_name", "My app GOOGLE PLAY"
applicationId "com.myapp.release"
}
TESTING {
resValue "string", "app_name", "My app TEST"
applicationId "com.myapp.test"
}
DEVELOPMENT {
resValue "string", "app_name", "My app DEV"
applicationId "com.myapp.dev"
}
Define Flavors
android {
defaultConfig {
applicationId "com.example.myapp"
}
productFlavors {
free {
applicationIdSuffix ".free"
}
pro {
applicationIdSuffix ".pro"
}
}
}
The key is the applicactionIdSuffix
android {
...
buildTypes {
debug {
applicationIdSuffix ".debug"
}
}
}
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.
I want to create an application with two flavours one with less features and one with more. How can i do it
Let us suppose there is
A - application
Flavour1 - feature1, feature2
Flavour2 - feature1, feature2, feature3
How to release one apk
and how user will install the application from play store how the user will know which flavour is going to be installed
There is nice documentation from google.
Multiple flavours
You should declare the flavors in the buildfile
android {
...
defaultConfig {...}
buildTypes {...}
productFlavors {
demo {
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
full {
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
}
After build two apk files will be created. They have different application id so you can publish them as two different applications to the Play Store. For example one free and one paid.
Features
There can be more solutions but the simplest one is to use buildConfigField.
productFlavors {
demo {
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
buildConfigField "boolean", "FEATURE_1", "true"
buildConfigField "boolean", "FEATURE_2", "false"
buildConfigField "boolean", "FEATURE_3", "false"
}
full {
applicationIdSuffix ".full"
versionNameSuffix "-full"
buildConfigField "boolean", "FEATURE_1", "true"
buildConfigField "boolean", "FEATURE_2", "true"
buildConfigField "boolean", "FEATURE_3", "true"
}
}
Then in java source code you can check if features are enabled:
if (BuildConfig.FEATURE_1) {
//run feature
}
Some othe approaches are described in the documentation.
I use Espresso for UI testing and I have multiple buildTypes in gradle file. After recording espresso test, when I'm trying to run test it throws Class not found:[package name] error:
Process finished with exit code 1
Class not found: "com.example.myapp.SplashActivityTest"Empty test suite.
This is my gradle file content buildType:
buildTypes {
debug {
debuggable true
applicationIdSuffix ".debug"
signingConfig signingConfigs.debug
}
development {
initWith debug
applicationIdSuffix ".dev"
resValue "string", "app_name", "DEV_My App"
buildConfigField 'String', 'BASE_URL', '"http://192.168.100.124:8080/"'
}
How can I solve this problem?