As you know, gradle stopped (official documentation) support VERSION_CODE and VERSION_NAME in the Gradle DSL. For more info click hire. So, I added this code (app build.gradle):
defaultConfig {
versionCode 1
versionName "1.0"
buildConfigField 'int', 'VERSION_CODE', "1" //fix issue
buildConfigField 'String', 'VERSION_NAME', "\"1.0\"" //fix issue
}
//..
buildTypes {
debugToast{
versionNameSuffix "-debug(Toasts)" //NOW DOES NOT WORK !!
}
}
//..
And my question: How fix versionNameSuffix method, because it doesn't work?
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"
}
}
I want to add the version code as a suffix of versionNameSuffix.
Currently, I have:
debug {
versionNameSuffix ".debug"
}
How can I have something like:
debug {
versionNameSuffix ".debug.versionCode"
}
My version code is based on the productFlavors:
productFlavors {
free {
versionCode 123
}
}
#Resolution: I move versionCode out from productFlavors to root level and use the accepted anwser to inject versionCode in versionNameSuffix
Create constant version code in your app build.gradle
def versionCode = 1
Then in your flavours
debug {
versionNameSuffix ".debug.${versionCode}”
}
Use the same version code in your defaultconfig also
defaultConfig {
versionCode ${versionCode}
}
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"
}
}
}
}
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"
}
}