Say I have the following build.gradle
android{
defaultConfig{
applicationId "com.example.base"
}
buildTypes{
release{
minifyEnabled true
}
debug{
applicationIdSuffix ".dev"
minifyEnabled false
}
}
productFlavors{
free{
applicationId "com.example.free"
}
paid{
applicationId "com.example.paid"
}
}
}
I want to add the resulting application id to strings.xml, like this:
resValue "string", "app_package", applicationId
So I can then use this value in intents targetPackage
defined in preferences xml
But the value changes depending on what block I put that line in:
By using the applicationIdSuffix, I need gradle to resolve the final id before I can use it. How do I do that?
Every Android app has a unique application ID that looks like a Java or Kotlin package name, such as com. example. myapp. This ID uniquely identifies your app on the device and in the Google Play Store.
You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. To start customizing each build variant with its own features and resources, however, you'll need to know how to create and manage source sets.
def isCurrentBuildType(buildType) { return gradle. getStartParameter().
A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.
Add this after productFlavors
within android
DSL:
applicationVariants.all { variant ->
variant.resValue "string", "app_package", variant.applicationId
}
In freeDebug
build this will be added in app/intermediates/res/merged/free/debug/values/values.xml
:
<string name="app_package" translatable="false">com.example.free.dev</string>
In paidDebug
:
<string name="app_package" translatable="false">com.example.paid.dev</string>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With