How can be defined that debuggable=true is enabled in releaseBuildConfig, but just for a specific set of flavors:
This is the example code, including the trial (which does not work):
flavorDimensions "project", "environment"
productFlavors {
basic {
dimension "project"
}
advanced {
dimension "project"
}
flavorDevelopment {
dimension "environment"
applicationId "ch.myproject.app.development"
debuggable true // this does not work
}
flavorTest {
dimension "environment"
applicationId "ch.myproject.app.test"
debuggable true // this does not work
}
flavorIntegration {
dimension "environment"
applicationId "ch.myproject.app.integration"
debuggable true // this does not work
}
flavorProduction {
dimension "environment"
applicationId "ch.myproject.app.production"
// just here debuggble has to be on the default (in buildTypes.debug = on AND in buildTypes.release = off )
// this is working
}
the "debuggable true" statements wont work in the code example above. But it should give you an impression, what I try to make.
The only productive Release I' gona make is the flavorProduction. There I'm using the default behavior which is working fine.
But all the other internal releases flavorDevelopment, flavorTest, flavor Integration, those I would like to have with enabled debugging capability.
I tried a second approach:
applicationVariants.all { variant ->
// setting all releases expecting the Production one to debuggable
if (!variant.buildType.name.contains("ProductionRelease")) {
variant.buildType.debuggable = true
}
}
But there I'm getting the message:
Error:(132, 0) Cannot set readonly property: debuggable for class: com.android.build.gradle.internal.api.ReadOnlyBuildType
Does anybody know how to configure this with gradle?
thanks in advance luke
debuggable
is a property of the BuildType
object, and not of the ProductFlavor
object, and so (as you have found), writing debuggable true
inside a product flavor will have no effect.
Generally you will have a debug
build type and a release
build type, and then you will have build variants like flavorProductionDebug
and flavorProductionRelease
. It sounds like that's not enough for you, and you need to have whatever is different between your debug
and release
build types be maintained while also having debuggable true
.
To achieve this, you can make a third build type.
buildTypes {
debug { ... }
release { ... }
releaseDebuggable {
initWith release
debuggable true
}
}
Now your releaseDebuggable
build type will be exactly like your release
build type, but debuggable!
This has the side-effect of creating a fooReleaseDebuggable
build variant for all of your product flavors. If you want to suppress all those except for flavorProductionReleaseDebuggable
, you could use the variantFilter
interface.
There is a way to achieve this, just set debuggable attribute to be true in manifest in every source set of expected product flavors.
Step 1: Create source set of product flavors.
New source set in app/src/[flavor-name] and create a AndroidManifest.xml in it. Just like the following:
Step 2: Define debuggable in manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:debuggable="false"
tools:ignore="HardCodedDebugMode" />
</manifest>
tools:ignore="HardcodedDebugMode"
is used to suppress warnings.
That's it, you're good to go. No need to touch your build.gradle files.
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