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

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

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.

No matching client found for package name (Google Analytics) - multiple productFlavors/application ids

I am setting up Firebase for my Android application and have run into a slight wrinkle/problem. I have multiple product flavors such as the standard dev, qa and prod. These product flavors share the same application id. However, I have one flavor where the application id is different:
productFlavors {
dev {
applicationId "com.acme.myandroidapp"
}
qa {
applicationId "com.acme.myandroidapp"
}
foo {
applicationId "com.acme.foo"
}
prod {
applicationId "com.acme.myandroidapp"
}
This is causing my gradle build to fail with a "No matching client found for package name 'com.acme.foo'" error.
I have looked at both: No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes and google-services.json for different productFlavors
Unfortunately, neither question deals with the wrinkle of having a different application id for a particular product flavor. I did try putting a copy of the google-services.json file at the base of each flavor but there was no joy.
Thoughts on how do you support different applicationIds with Google Services under Android?
You can Add app for both the application Ids in Project setting in Firebase Console.
By doing so the new google-services.json file will contain two client-info, 1 for each application ID.
Putting a copy of the google-services.json file at at the base of each flavor should solve the issue.

Package naming convention Android

I have an Android App, which has two flavors: Basic and Advanced.
The Basic is already on the AppStore, with a package name of form com.domain.something. I would like to publish the second as com.domain.something.advanced. Is it possible? Or is the fact that the second is a sub package of the first would cause trouble?
Yes, this is possible and will not cause any problems in the Play Store.
You will want to read the Configure Build Variants guide for more information on setting up a product flavor for your "advanced" version. You can use the applicationIdSuffix in your build types or product flavors to set a suffix on your application ID for that particular variant.
Your build.gradle will end up looking something like this:
android {
defaultConfig {
applicationId "com.domain.something"
}
buildTypes {...}
productFlavors {
basic {...}
advanced {
applicationIdSuffix ".advanced"
}
}
}
You can then either programmatically check your product flavor with the generated BuildConfig class, or put your code for the advanced version in the advanced product flavor's source folder (/src/advanced/java, /src/advanced/res, etc.).

Create separate apk for separate flavor in android to run on same device

I have already asked similar question But could not find what i seek . Hence asking again .
I want to run separate flavor apk on same device simultaneously.
I have used build.gradle(app) to create different flavors of apk. But installing different flavors of same apk overrides the previous one. I want to create different apks to run on same device simultaneously. I want to create different apk with different appicon which can be installed on same device and run simultaneously. Any link or tutorial or direct help is appreciated.
My build.gradle is as below
productFlavors {
production {
applicationId
"com.abc.def"
buildConfigField 'String', 'HOST', '"http://example.com/api/"'
}
staging {
applicationId
"staging.com.abc.def"
buildConfigField 'String', 'HOST', '"http://example.com/api/"'
}
backendtesting {
applicationId
"backendtesting.com.abc.def"
buildConfigField 'String', 'HOST', '"http://example.com/api/"'
}
}
Do not put line breaks between the gradle command and it's argument. It will read each line separately since line breaks are command separators for gradle.(like how ; is for java)
For example, use:
applicationId "com.abc.def"
instead of
applicationId
"com.abc.def"
This post explains step by step how to configure your directory structure and gradle file.
The main steps are:
add the product flavours container to the app build.gradle file
productFlavors {
free {
applicationId "antoniocappiello.com.buildvariantsexample.free"
}
paid {
applicationId "antoniocappiello.com.buildvariantsexample.paid"
}
}
create inside src a directory with the exact name of the product flavour that you want to look different from the main variant, for example with the configuration at step 1 the directory name could be paid or free . And inside that directory create the subfolder res/drawable where you are going to place your new app launcher icon.
Directory structure example
You can set different applicationId for different flavors. In this way different flavors will be treated as different applications and will not overwrite each other when you install them on same device.
As an example, following snippet will create two flavors, prod and dev with different app packages. You can install them both together on the device.
productFlavors {
dev {
applicationId "com.swagata.devbuild"
}
prod {
applicationId "com.swagata.prodbuild"
}
}

Categories

Resources