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

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"

Related

Make Android build variants with different package and application id

Dears I want to make every build variant with a separated package name and application id because i need to upload app to google play testing env but i can't becuase of it's have project same package for published app on store
you don't need to change the package name, you can add a suffix to each variant like this in app/build.gradle:
debug {
...
applicationIdSuffix = ".debug"
}
anotherFlavor {
...
applicationIdSuffix = ".another"
}
or you can change the application id like this :
debug {
applicationId "com.app.debug"
}
In app/build.gradle, you setup
productFlavors {
dev {
dimension 'api'
applicationId "com.abc.dev"
targetSdkVersion 29
}
production {
dimension 'api'
applicationId "com.abc"
targetSdkVersion 29
}
}
Refer: enter link description here

Android and Firebase: different environments for different testing cycles

I am currently developing my first Android application ever, and it is the Android/Kotlin version of an iOS application I already developed. I created 3 different Firebase projects to have independent realtime database instances for each environment:
com.myapp.debug is only used by me for development
com.myapp.beta should be used for alpha and beta testing
com.myapp should be only for the production application that will be released publically on the Play Store
When I was looking into plugging these 3 environments in my Android app, I read that I should use product flavors for that, so here is how I configured my build:
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.derbigum.approofreferences"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "dev", "qa", "prod"
productFlavors {
dev {
dimension "dev"
applicationId "com.derbigum.approofreferences.debug"
}
qa {
dimension "qa"
applicationId "com.derbigum.approofreferences.beta"
}
prod {
dimension "prod"
applicationId "com.derbigum.approofreferences"
}
}
}
And of course I created the corresponding subfolders in src to store the various versions of google-services.json I got for each project.
I did all my development with that and it worked so far: development data was created in the right database.
But now I want to do a first closed alpha release but I'm confused as to how I should generate my APK. I have only 2 build variants:
devQaProdDebug
devQaProdRelease
Maybe I made a mistake in configuring flavorDimensions? Maybe it's something else. Can someone please help me figure out if my setup is OK, and if so how I should go about building the closed alpha version of my app and release it to my internal users for testing?
I think what you want here is not three dimensions for three environments, but just one dimension for environment, with three flavors:
flavorDimensions "env"
productFlavors {
dev {
dimension "env"
applicationId "com.derbigum.approofreferences.debug"
}
qa {
dimension "env"
applicationId "com.derbigum.approofreferences.beta"
}
prod {
dimension "env"
applicationId "com.derbigum.approofreferences"
}
}
This will get you build variants for each environment.

Android flavors with different applicationId broke application behavior and look

I am using following build.gradle
apply plugin: 'com.android.application'
def final appId = "com.example.app"
android {
compileSdkVersion 23
buildToolsVersion '24.0.1'
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId appId
buildConfigField "String", "DBNAME", "\"mydb.db\""
}
testOptions {
unitTests.returnDefaultValues = true
}
buildTypes {
release {
minifyEnabled false
proguardFile 'proguard-rules.pro'
}
}
productFlavors {
rel {
minSdkVersion 14
applicationId = "${appId}"
buildConfigField "String", "DBNAME", "\"mydb.db\""
targetSdkVersion 23
versionCode 33
versionName '1.4'
}
dev {
minSdkVersion 14
applicationId = "${appId}.dev"
buildConfigField "String", "DBNAME", "\"mydb_dev.db\""
targetSdkVersion 3
versionCode 1
versionName '1.4-beta'
}
}
}
...
I have not copied code from main to rel and dev source sets, and I have just created separate files for each flavor: res/values/strings.xml, res/values/colors.xml, google-service.json.
The application builds well, with different applicationId and installs as separate on the same device.
For the rel flavor everything works well, and it has applicationId = 'com.example.app' equal to original package name and to actual source package name.
But I obtain very strange behavior and look for the dev flavor, which becomes applicationId = 'com.example.app.dev'
Firstly, I see that animations are not working properly, because it seems that they become wrong coordinates.
Secondary, I have many fragments with dynamically inflating views and they are showing partly or not showing at all - differently at different run.
I suggest that the issue is that I have the same package name for classes and probably there emerges so ambiguous class identification.
I see that getContext() returns the same class 'com.example.app.MainActivity' for both flavors and I think this is matter.
I wouldn't like to copy all sources under each source set because i don't need to make changes there - code still the same.
What is a solution?
It was a mistyping that kills many hours to resolve...
I had pointed targetSdkVersion 3 rather targetSdkVersion 23
(I am surprised that it was building at all)
The Issue is solved, Android Flavors are magnificent!

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
}

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