I need to set my application ID for a build variant.
I have a defaultConfig in my build.gradle, which sets the applicationId
defaultConfig {
applicationId "mycompany.mainappname"
minSdkVersion 12
Now I need to set the application ID to "mycompany.mainappname_fullversion". (no dot between mainappname and _fullversion)
I need this, because I have published my fullversion to googleplay 4 years ago with this name.
How can I do this ?
I tried to use the applicationIdSuffix syntax in my buildTypes Section to add the suffix, but it also adds me an "." befor the suffix, which is in my case wrong -> "mycompany.mainappname_fullversion._fullversion"
buildTypes {
full {
applicationIdSuffix '_fullversion'
I also tried to set the applicationID with applicationId "mycompany.mainappname_fullversion" in my build section, but i throws errors.
How can I simply set the applicationID to ""mycompany.mainappname_fullversion" in a build ?
Can someone help ?
Place a separate manifest in each build variant's directory under src.
Try removing applicationId from defaultConfig and add applicationId in each of buildTypes
buildTypes {
full {
applicationId 'mycompany.mainappname_fullversion'
Related
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"
I want to upload a new version of my app, but I can't because I added flavors so the package name has changed from:
com.myapp.android
to
com.myapp.android.flavor1
Inside my build.gradle:
productFlavors {
main {
applicationId 'com.myapp.android'
versionName '1.0'
versionCode 4
}
flavor1 {
applicationId 'com.myapp.android.flavor1 '
versionName '1.0'
versionCode 5
}
}
If I change the applicationId of flavor1 to 'com.myapp.android' I get this error:
Error:Execution failed for task ':app:processMainDebugGoogleServices'.
No matching client found for package name 'com.myapp.android'
So my question is, should I try to fix that error (and if yes how?) or is there any other work around ?
I haven't tried this, but reading the docs it seemd that just taking "applicationId" out of both flavor sections (main and flavor1) should work fine.
The new applicationId should be in your google-services.json as well.
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!
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.
Thanks in advance.
Change the PackageName of the flavor
Sample Gradle File
apply plugin: 'com.android.application'
android {
lintOptions {
abortOnError false
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
buildTypes {
debug {
minifyEnabled false
zipAlignEnabled true
}
release {
minifyEnabled true
zipAlignEnabled true
}
}
productFlavors {
Flavor1 {
applicationId "com.falvor.one" //This is where you change the package name
}
Flavor2 {
applicationId "com.falvor.two"
}
}
}
Flavor Hierarchy in Android
- src/main/java
- src/flavor1
--------------Java
----------------Your java files
--------------res
----------------Drawable
src/flavor2/java
For more understanding, follow this link
You need to create new productFlavors in your gradle file, like this;
productFlavors {
Flavor1 {
applicationId 'com.project.fl1'
signingConfig signingConfigs.xx
versionCode 1
}
Flavor2 {
applicationId 'com.project.fl2'
signingConfig signingConfigs.xx
versionCode 1
}
Flavor3 {
applicationId 'com.project.fl3'
signingConfig signingConfigs.xx
versionCode 1
}
}
The important thing here is to give each one a unique applicationId, they can then be installed on the same phone.
This post explains exactly how to achieve what you want step by step.
Most importantly:
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
By default, Gradle build.gradle usually looks like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.xyz.android"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
...
Is there a way to make defaultConfig.versionCode and defaultConfig.versionName dynamic, instead of static?
By dynamic I meant to bind them to the Manifest so these two values update when the same Manifest values update.
It seems that in Gradle we don't have to touch Manifest. All we have to do is to set Gradle and it will set Manifest. That is the main reason why Gradle projects don't have set these values in Manifest by default.