Android : Install different flavors with same package names - android

I developed an android app with 3 different flavors (production,testing, training). Almost 99% of the source codes are identical. Only a single file in assert folder with server urls are different for each flavor. The flavors work perfectly. But i would like the app to install all 3 apps in the device without overwriting each other. Since the package name of the project is the same for all the flavors, it's overwriting the app when i install difference flavors.
Any ideas or suggestions ? Thanks in advance.

Anyway just by changing the package name in the build.gradle it works.
productFlavors {
production {
applicationId = "<your-package-surfix>.production"
}
testing {
applicationId = "<your-package-surfix>.testing"
}
training {
applicationId = "<your-package-surfix>.training"
}
}
In AndroidManifest.xml use full package name when define a activity/service/receiver.

Related

How to upload 2 different flavor apps in 1 playstore project

Following is my app package name
com.test.myapp
and I have created 2 product flavors, 1 for development & 1 for production like following.
productFlavors {
dev {
applicationId = "com.test.myapp.dev"
}
production {
applicationId = "com.test.myapp"
}
}
It works fine, when i launch app from android studio, it also creates signed apk fine, but when i try to upload development apk on play store, it gives following error message.
Your APK or Android App Bundle needs to have the package name
com.test.myapp.
Technically it is not possible, Google not allows this, you need to create 2 apps on Google play for this. But why you need flavor for development with different package name? does Google's Alpha testing not solve your problems?
Edit:
Based on comments the issue was how to load different strings.xml based on build config without creating new package name.
Solution:
flavorDimensions "dev"
productFlavors {
dev {
flavorDimensions "dev"
}
prod {
flavorDimensions "dev"
}
}
Create new strings.xml resource in dev source set
\src\dev\res\values\strings.xml
I have uploaded demo project:
https://github.com/pavelpoley/FlavorTest
More info you can find in docs:
https://developer.android.com/studio/build/build-variants#sourcesets

User flow for providing multiple versions (environments) of mobile app to end users

We are trying to provide multiple environments to our end users and want to create one single bundle for both IOS and Android. Currently we have a hidden feature (clicking on the version number to open an environment selection screen: Dev, QA, UAT or Prod). However, I am wondering if there are better or recommended ways of achieving this same effect somehow.
Thanks!
I can help you with Android on managing Environments using Gradle file.
Let's say you have a app with package name - com.company.sampleapp
In gradle your applicationId will be com.company.sampleapp
Now we can create different flavors for different environment and we can also have different applicationId as shown below.
android {
flavorDimensions "default"
productFlavors {
production {
dimension "default"
applicationId 'com.allegion.leopard'
}
//App will have package name appended with .qa
qa {
dimension "default"
applicationId 'com.allegion.leopard.qa'
}
//App will have package name appended with .dev
dev {
dimension "default"
applicationId 'com.allegion.leopard.dev'
}
}
}
Once this is done, you can choose build variants and create APK for that build. Added image for clarity
Hope this helps.

how to run same android app with different name in one device?

I build a two apk from same source code . both have Different name,icon background .i changed only UI and app name tow app have same package,
my problem is I can't install this both app on same device .when I try to install facing error message .
How I can run this two application (build from same source just change name and icon) on same device .? what are the values I should change in application to run this app separately .?
Kindly Give me a hand with this
You need to change package name to make Android System detect your 2nd app as different from first. App name doesn't matter.
Use productFlavors in your build.gradle file.
android {
productFlavors {
dev {
applicationId "com.company.app.dev" // package name for dev flavor
}
beta {
applicationId "com.company.app.beta" // package name for beta
}
production {
applicationId "com.company.app" // package name for production
}
}
}
All your files can still be in your src/main dir. Flavor specific changes can be placed in src/beta etc.
you just have to change the name and the package name of your second instance of the application.

Android Studio. Organizing project for Google Play: Same application, different assets

I developed a "template" application that I want to distribute on Google Play using different names and assets depending on the specific domain I'm targeting the app for (general, "domain1", "domain2", ...).
I have read in other posts that the first thing to do is to change the package name for each new application (in fact Google Play uses it as index, so it can NOT be repeated).
The easy solution I see is to create a new project and change the package name and assets, but this is quite "bloated". I'm wondering whether it's possible somehow to use a single AndroidStudio project to generate the "template application" and the "domain specific" ones.
You can Define product flavors in the build file like general , domain1 ,domai2, .....
...
android {
...
defaultConfig { ... }
signingConfigs { ... }
buildTypes { ... }
productFlavors {
general {
applicationId "com.buildsystemexample.app.general"
versionName "1.0-demo-general"
}
domain1 {
applicationId "com.buildsystemexample.app.domain1"
versionName "1.0-full-domain1"
}
...
...
}
}
...
As you see, all flavours will have different applicationId.
And moreover , you can have different resources or src or assets for your flavors as you want.
All you have to do is build the flavor you want from android studio.
Read more here. https://developer.android.com/tools/building/configuring-gradle.html

(Cordova/Phonegap) Android splash screen not being shown using Android Studio builds

I have the following product flavors in module's build.gradle
productFlavors {
pro {
applicationId "com.icounttimer.android"
}
free {
applicationId "com.icounttimer.android.free"
}
}
The package structure of my app module is:
src/main/java/com/icounttimer/android/MainActivity.java
Building pro-debug.apk shows the splashscreen correctly. However, free-debug.apk does not show the splashscreen.
Changing the applicationId of 'free' flavor to 'com.icounttimer.android' resolves the issue. But when using a different applicationId, the splash screen won't be shown.
Environment:
CordovaLib: v3.6.3
Android Studio 1.0 RC4
What is the reason for this behaviour and how to resolve this issue?
The reason which I found is as follows:
Changing applicationId via build.gradle, changes the app's package name.
Note that it is different from the package structure of the app which remains unaltered during different build variants.
The app package structure, in this case, is unaltered: src/main/java/com/icounttimer/android/MainActivity.java
Diving through the code, I found out that the showSplashScreen() methods in CordovaActivity.java (part of CordovaLib) get the resources as follows:
this.splashscreen = getResources().getIdentifier(splash, "drawable", getClass().getPackage().getName());
The third arguments for getIdentifier(...) method is the package name of app.
getClass().getPackage().getName()
gets the pkgName based on package structure which always returns 'com.icounttimer.android' no matter which build variant it is.
To fix this, replace both of its occurences in CordovaActivity.java with:
this.getPackageName() //returns the name of the application pkg which is the applicationId

Categories

Resources