In my build.gradle I have the follwing buildTypes:
buildTypes {
release {
//debuggable true
minifyEnabled false
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER_DOMAIN", "\"api.example.com\""
}
debug {
minifyEnabled false
buildConfigField "String", "SERVER_DOMAIN", "\"api.local\""
}
staging {
initWith debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER_DOMAIN", "\"https://api.staging.example.com\""
}
}
Also the api.local I use self-signed certificates that I configure them into the network-security-config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!-- local -->
<domain-config>
<domain includeSubdomains="true">api.local</domain>
<trust-anchors>
<certificates src="@raw/api"/>
</trust-anchors>
</domain-config>
<!-- /local -->
</network-security-config>
Also, in app/src/main/res/raw I place a file named api.crt where it is the self-signed certificate.
But once wither I build a release or a staging variant I do not want the certificates to be shipped. Is there a way to do so? Also how I can specify per-variant network-security.xml
One way is to use a CI/CD pipeline and delete the certificates whilst I replace the network-security-config.xml with a default one before I run:
./gradlew assembleRelease
Or
./gradlew assembleStaging
But this approach may not scale if app needs to be built in my (coleagues) local machine at any variant. Is there a way to do so?
