Android flavors with different applicationId broke application behavior and look - android

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!

Related

Why is the value for ${applicationName} not supplied after migrating my Flutter app to Android embedding v2?

I tried to immigrate a deprecated flutter application, but after following the steps provided on github im getting this
C:\Users\personal\AndroidStudioProjects\flash-chat-flutter\android\app\src\main\AndroidManifest.xml:10:9-42 Error:
Attribute application#name at AndroidManifest.xml:10:9-42 requires a placeholder substitution but no value for <applicationName> is provided.
C:\Users\personal\AndroidStudioProjects\flash-chat-flutter\android\app\src\debug\AndroidManifest.xml Error:
Validation failed, exiting
I ran into this as well. In my case it was because I had set manifestPlaceholders the "usual" way, by assigning with = (as all examples seem to do):
In android/app/build.gradle:
android {
⋮
defaultConfig {
applicationId "com.example.my_app"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// This right here!
manifestPlaceholders = [someKey: "#string/some_value"]
}
⋮
}
It turns out that multidex support introduced the need to dynamically determine the application name, hence the ${applicationName} placeholder in the manifest.
That value is determined by the Flutter Gradle plugin here by means of manifestPlaceholders, so if you replace the value by reassigning it then you will run into this issue. The fix is simple: add your values to the existing ones with += like so:
android {
⋮
defaultConfig {
applicationId "com.example.my_app"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// Fixed now! Note the plus!
manifestPlaceholders += [someKey: "#string/some_value"]
}
⋮
}
I got the same error:
You need to add this to your build.gradle (YourFlutterProject/android/app/build.gradle)
buildTypes {
release {
manifestPlaceholders = [applicationName: "android.app.Application"]
}
debug {
manifestPlaceholders = [applicationName: "android.app.Application"]
}
build{
manifestPlaceholders = [applicationName: "android.app.Application"]
}
}

SDK levels for lollipop

what are the best apk level to run a app in a android lollipop 5.1 version. Here is what I currently having
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.locationtracker2019"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
As per your Question your application is running in the minSdkVersion means that your minimum version support your app.
targetSdkVersion is the main way Android provide forward compatibility not applying behavior change unless the targetSdkVersion is update.
It should be emphasized that changing your compileSdkVersion does not change runtime behavior. While new compiler errors/warnings may present when chang your compileSdkVersion, your compileSdkVersion is not included in your APK: it is purely used at compile time.
For more information about, What is API Level?
I hope it'll help you...!

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

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"

Setting ApplicationID for every build variant

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'

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
}

Categories

Resources