add multiple google-service.json file in product flavor - android

I have 3 different Firebase projects. and it has to be used in 4 google-service.json use in product flavors. but i get an below error
File google-services.json is missing. The Google Services Plugin cannot function without it.
for below structure
And if I put the google-service.json in the app folder then i get this error
No matching client found for package name 'com.example.app1'
for below structure
build.gradle
flavorDimensions "category", "app"
productFlavors {
mcq1 {
applicationIdSuffix ""
dimension "category"
}
mcq2 {
applicationIdSuffix ""
dimension "category"
}
mcqappgj {
dimension "app"
applicationId "com.example.app1"
versionCode 9
versionName "1.0.7"
}
mcqappen {
dimension "app"
applicationId "com.example.app2"
versionCode 7
versionName "1.0.6"
}
gpscapp {
dimension "app"
applicationId "com.example.app3"
versionCode 2
versionName "1.0.1"
}
eemcq {
dimension "app"
applicationId "com.example.app4"
versionCode 2
versionName "1.0.1"
}
}

Related

Getting package name conflict with different application ids of the same app

I have an app with two flavors, each with a unique application id, according to the docs this is how to install both versions of the app on the same phone. But I keep getting the package name conflict error while I try to install either of them while the other one is already installed
Flavor settings
defaultConfig {
applicationId "com.kc.mb.vr"
multiDexEnabled true
minSdkVersion 19
targetSdkVersion 26
versionCode 14
setProperty("archivesBaseName", "vr4.25.1")
}
flavorDimensions "default"
productFlavors {
dev {
versionName "4.25.1"
applicationId "com.kc.mb.vr.dev"
dimension "default"
}
prod {
applicationId "com.kc.mb.vr"
versionName "3.1.2"
dimension "default"
}
}
After installing, I checked with the package name viewer that shows the app with the dev flavor has a packagename + ".dev" and the one with prod has a different package name. But both of them can not be installed together.
Is there any step that I might have missed ?
For example,in your dev flavor,delete applicationId "com.kc.mb.vr" and add following code:
applicationIdSuffix ".dev"
then your dev's package name will be "com.kc.mb.vr.dev"

Using my custom class in build variants

I have created 4 different flavours in build variants in my app.
I have added version and suffix in the configuration in my app's build.gradle.. Below is the code:
productFlavors {
qa {
applicationIdSuffix ".qa"
versionCode 1
versionName "1.0"
//manifestPlaceholders = [application: ".utils.Application"]
}
demo {
applicationIdSuffix ".demo"
versionCode 1
versionName "1.0"
//manifestPlaceholders = [application: ".utils.Application"]
}
dev {
versionCode 1
versionName "1.0"
//manifestPlaceholders = [application: ".utils.Application"]
//signingConfig signingConfigs.release
}
uat {
applicationIdSuffix ".uat"
versionCode 1
versionName "1.0"
//manifestPlaceholders = [application: ".utils.Application"]
}
}
In my app, I use a file APIAddresses.java for selecting the URLs to hit according to the environment.
Is there any way I can use only this file out of all the source code in build.gradle only to configure URLs for build variants?
May be create different copies of this file for each build variant, something similar to this.
productFlavors {
qa {
applicationIdSuffix ".qa"
versionCode 1
versionName "1.0"
APIAddresses_QA
}
demo {
applicationIdSuffix ".demo"
versionCode 1
versionName "1.0"
APIAddresses_DEMO
}
}
Thank you!
Yes you can use one version of your file APIAddresses.java for all your variants.
In your build.gradle, add
flavorDimensions "main"
Put your APIAddresses.java file in the app\src\main directory.
In your code, you can then generate different URLs for each variant using the variable
BuildConfig.FLAVOR
If you don't want to add lot of if-else conditions in your classes, you can add new buildConfigField to each flavor:
productFlavors {
qa {
applicationIdSuffix ".qa"
versionCode 1
versionName "1.0"
buildConfigField "String", "SERVER_URL", '"https://server1.com"'
}
demo {
applicationIdSuffix ".demo"
versionCode 1
versionName "1.0"
buildConfigField "String", "SERVER_URL", '"https://server2.com"'
}
...
}
After that you can call BuildConfig.SERVER_URL on Java side, and according to each flavor, it should return proper URL in my example

Android apk version name

Following is my build.gradle file:
...
defaultConfig {
applicationId "app.com.foo.player"
minSdkVersion 18
targetSdkVersion 23
versionCode 1 // increment with every release
versionName "Foo-1.0" // change with every release
setProperty("archivesBaseName", "$versionName")
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
...
I have few question related to version name of android apk:
When I build the project, the generated apk name is Foo-1.0-debug.apk. Where from is 'debug' coming from, what does it signify, and how do I avoid/change that ?
How do I generate different names for dev and prod version of apps ?
Is there a way I can automatically increment my version number and version name for each build ?
Thanks in advance.
To generate different name for developmen and product, u can use productFlavors,refer the below link.
https://developer.android.com/studio/build/build-variants.html
In gradle ,
productFlavors{
releaseBuild{
buildConfigField "String", "APP_NAME", '"SAMPLE_APP_PRODUCT"'
}
debugBuild{
buildConfigField "String", "APP_NAME", '"SAMPLE_APP_DEBUG"'
}
}
After setting in gradle, change the BuiltVariant and run the program
With question 1 and 2 you can goto Project Structure select tab Flavors and Build Type to setup config for build.
With question 3 you can make a script in build.gradle in project then use in module. Here I use current time in second as a example:
in project:
ext{
minSdk = 14
targetSdk = 23
verCode = getVersion();
verName = "Foo-1.0"
}
def getVersion() {
return new Date().getTime() / 1000;
}
In module
defaultConfig {
minSdkVersion minSdk
targetSdkVersion targetSdk
versionCode verCode
versionName verName + verCode
}

How to set different version number in android build types?

I need to set two different android build types i.e. staging and release.
defaultConfig {
applicationId "com.app.testing"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER_URL", '"http://testing.com"'
}
dev {
applicationIdSuffix ".dev"
buildConfigField "String", "SERVER_URL", '"http://testing.com"'
}
Now I want to add versionName for each build type. How can I do that?
Edit
productFlavors{
release {
versionname = "1.0"
}
dev{
versionname = "1.0"
}
}
You can also use different version names for each build type without using flavors
In your app-module build.gradle:
defaultConfig {
...
versionName ""
}
...
buildTypes {
debug {
...
versionNameSuffix 'debug-version-1'
...
}
release {
...
versionNameSuffix 'version 1'
...
}
}
versionName "" did the trick.
You can use productFlavors like below:
productFlavors
{
test
{
applicationId 'com.example.test'
versionName '1.0.0.test'
versionCode 1
}
product
{
applicationId 'com.example.product'
versionName '1.0.0.product'
versionCode 1
}
}
You can define it under your default config. You can change from build variants. You can combine your build types with flavors.
Good luck.
The version code could be in minor versions to such as the following:
defaultConfig {
applicationId "com.app.testing"
minSdkVersion 19
targetSdkVersion 23
versionCode 3.2.1
versionName "1.0"
}
In the example above 3 denotes a major release which drastically updates the way an app would look like or its functionality. 2 denotes a bug fix/improvement which updates the app in some way or another, while 1 denotes a minor update or fix.
Hope this helps.
I need to set two different android build types i.e. staging and
release.
Defining buildTypes
As in your question above, you have correctly defined your two buildTypes, "release" and "dev".
Now I want to add versionName for each build type. How can I do that?
Iterating through buildTypes
A clean and more programmatic way to define your versionName (or any other defaultConfig parameter for that matter) for different buildTypes, is to iterate through all application variants and perform a specific action for your buildTypes using if statements:
android {
...
defaultConfig {
...
applicationVariants.all { variant ->
if(variant.buildType.name == "release") {
//Release
versionName "1.2.3"
} else if(variant.buildType.name == "dev") {
//Dev
versionName "3.2.1"
}
}
}
}

Android - change app version name based on flavor

I want to change the app versionName to whatever is defined in the AndroidManifest file for the specific flavor I'm building.
So if I'm only building one of the 4 defined flavors I have, like:
gradle assembleFlavor1Debug
I was expecting Flavor1 to have the same version name as the one defined for its specific manifest (because of the merging of manifest files), but that's not happening.
How can I know, during build time, which specific flavor is being built?
Because if I know what flavor is being run,
I can extract the respective versionName from the manifest and set it on android.defaultConfig.versionName,
which solves my problem.
As of at least Android Studio 3.1.1 you can do this...
defaultConfig {
versionName "1.0.0"
}
flavorDimensions "dimen1", "dimen2"
productFlavors {
'flavor1' {
dimension "dimen1"
versionNameSuffix "-F1"
}
...
'flavorA' {
dimension "dimen2"
versionNameSuffix "-FA"
}
}
Then for variant flavor1FlavorA the versionName would be 1.0.0-F1-FA
https://developer.android.com/studio/build/build-variants#product-flavors
You can do this in this way
productFlavors
{
test
{
applicationId 'com.example.test'
versionName '1.0.0.test'
versionCode 1
}
product
{
applicationId 'com.example.product'
versionName '1.0.0.product'
versionCode 1
}
}

Categories

Resources