Change package name (not only applicationId) for build flavor - android

When building multiple whitelable apps on the same codebase it's easy to use the build flavor mechanism of Android Studio. I can easily set a new applicationId in build.gradle file.
android {
productFlavors {
original {
applicationId "com.original.myapp"
}
whitelable {
applicationId "com.whitelable.myapp"
}
}
}
Everything's nice BUT the package name of the whitelable app is still com.original.myapp and the component name of the main activity is com.whitelable.myapp/com.original.myapp.MainActivity. Everybody can see that the whitelable app is build upon the original app.
Is the a way to replace the package name for the build flavor so the original package name at least doesn't appear on the flavored app's component names?

The question was asked a long time ago but I'd like to answer it for new folks who will investigate.
First you have to create 2 versions with Flavors.
Then, if you are using it, you need to create the data for the version you just created in the "client": [] section in your google-service.json file. (You can also create a separate google-service.json file for both in their own package folders.)
Then use ${packageName} instead of explicitly typing your package path in the Manifest file with your package path.
I was able to create 2 completely different packageNames by following this way.
Flavors;
flavorDimensions "default"
productFlavors{
product1{
applicationId "com.product.package"
}
product2{
applicationId "com.white.label"
}
}
google-service.json;
I cannot share the google-service.json file, but the data under "client" in the google-service.json file you will receive for your new project via Firebase should be copied and added to the "client" as the second data under the google-service.json file in your project. Sample;
"client": [
{
"client_info": { //Old App Info
data...
},
...
},
{
"client_info": {
//New App Info
data...
},
...
}
]
Manifest;
com.project.package.fileprovider
use this instead
${packageName}.fileprovider

Related

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.

Manage same Project with different package name in GIT

I have a project lets say Project A( Main Project/ Master). I need to create same projects but with same code and different package name Project B and Project C.
If the changes are applicable to all then I will make changes in Project A, so that if I update Project B and Project C automatically they should get the changes.
But if any customization came for project level then I need to change in Project B only. It should not affect to Project A or C. Like this how can I handle all three projects using git.
Will it work with using branches.?
Thanks in Advance...
Use build variants in your code, instead of relying on multiple branches in git. This way, a single source code can be generated as multiple applications.
android {
compileSdkVersion ...
buildToolsVersion ...
defaultConfig {
applicationId "com.yourapp"
...
}
// Specify the build dimension and flavors
flavorDimensions "type"
productFlavors {
typeA {
dimension "type"
applicationIdSuffix '.typea' // Add this to differentiate the application ID
versionNameSuffix "-typea" // Add this to differentiate version naming
}
typeB {
dimension "type"
applicationIdSuffix '.typeb'
}
typeC {
dimension "type"
applicationIdSuffix '.typec'
}
}
}
It doesn't matter if your classes are in the same package, as long as your application ID differs, you can install multiple version of the app at the same time on your device.
To build each specific app, simply change the chosen variant in Android Studio.
For specific flavor implementation in your code, you can use BuildConfig.FLAVOR to check which flavor the current application is.
when (BuildConfig.FLAVOR) {
"typeA" -> {
// Do stuff for typeA app
}
"typeB" -> ...
"typeC" -> ...
}

Can an app have multiple google-services.json files?

I have an android sdk which requires the app using it to have google-services.json file in its project directory.
I am wondering what will happen if the app already has a google-services.jsonfile from its implementation and is receiving FCMs from its own google developers console.
Can an app have multiple google-services.json file for the same flavor.
Can an app receive FCM's from two different google developers console account? or How can an app receive FCM's from two different google developers console?
I am just trying to explore ways as to how I can send FCM from my server to the app without making the app change its underlying design.
Downvoting must be accompanied with reason.
If you have multiple flavors configured in your app is intende to say that you will create multiple apps with different package name, for example:
flavorDimensions "mysite"
productFlavors {
elnorte {
applicationId 'com.jorgesys.creatorhdplayer'
manifestPlaceholders = [appName: "Creator hd player"]
dimension "mysite"
}
reforma {
applicationId 'com.jorgesys.creatorhdfree'
manifestPlaceholders = [appName: "Creator hd free"]
dimension "mysite"
}
mural {
applicationId 'com.jorgesys.creatorhd'
manifestPlaceholders = [appName: "Creator hd"]
dimension "mysite"
}
}
therefore you need to add diferent google-services.json files in your proyect for every application that needs google play services :
The google-services.json file is related to the package name so you just need one file for every application. The same if you have only one flavor configured (one 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

Android : Install different flavors with same package names

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.

Categories

Resources