Android buildTypes multiple debug modes - android

I have three build types, and I am trying to get the staging build type to run but I am getting the following error:
Error: The apk for your currently selected variant (app-staging-unsigned.apk) is not signed. Please specify a signing configuration for the variant (staging).
Is there a way for me to run staging without signing, as like a second debug?
android {
buildTypes {
debug {
buildConfigField "String", "SERVER", '"dev.gamesmart.com"'
}
staging {
buildConfigField "String", "SERVER", '"staging.gamesmart.com"'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER", '"gamesmart.com"'
}
}
}

Try:
android {
buildTypes {
debug {
buildConfigField "String", "SERVER", '"dev.gamesmart.com"'
}
staging.initWith(buildTypes.debug)
staging {
buildConfigField "String", "SERVER", '"staging.gamesmart.com"'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER", '"gamesmart.com"'
}
}
}
This says "have staging start as a clone of debug, then we'll modify from there", so staging should apply the debug signing config.

Related

How to define a shared build variable?

I'm trying to set up custom variable for each build type.
My build.gradle file looks like this:
buildTypes {
each {
buildConfigField "string", "SHARED_URL", "https://stackoverflow.com/"
}
debug {
buildConfigField "string", "PRIVATE_URL", "https://debugoverflow.com/"
}
release {
buildConfigField "string", "PRIVATE_URL", "https://releaseoverflow.com/"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
And I want to have an access to the SHARED_URL in my code by final String sharedUrl = BuildConfig.SHARED_URL; both in the debug and in the release build. So, how can I achieve this goal?
P.S. I'm understand that I can just copy variable SHARED_URL in the both builds, but I don't want to boilerplating.
You can put your common buildConfigField in defaultConfig:
android {
defaultConfig {
buildConfigField "string", "SHARED_URL", "https://stackoverflow.com/"
}
buildTypes {
debug {
buildConfigField "string", "PRIVATE_URL", "https://debugoverflow.com/"
}
release {
buildConfigField "string", "PRIVATE_URL", "https://releaseoverflow.com/"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
SHARED_URL will now be available for all build variants.

How configure a different buildType for a flavor with gradle

I have two different flavor's, RQT & PRD.
And for one of them, I want to disable proguard configuration (for RQT, disable proguard for both buildTypes).
Like add conditioning ? Is something like that is possible ?
android {
...
flavorDimensions("server")
productFlavors {
rqt {
dimension "server"
applicationIdSuffix ".rqt"
}
prd {
dimension "server"
applicationIdSuffix ".prd"
}
}
...
buildTypes {
debug {
(__if (flavor != RQT) then do proguard config...__)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'proguard-debug-project.txt'
}
release {
(__if (flavor != RQT) then do proguard config...__)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'proguard-release-project.txt'
}
}
...
}
You could create additional Build Types, e.g. debugNoProguard, releaseNoProguard, etc.
android {
variantFilter { variant ->
def needed = variant.name in [
'rqtDebugNoProguard',
'rqtReleaseNoProguard',
'prdDebug',
'prdRelease'
]
variant.setIgnore(!needed)
}
buildTypes {
debug {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'proguard-debug-project.txt'
}
debugNoProguard {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
....
}
}
Then instead of building rqtDebug you would build the variant rqtDebugNoProguard or prdDebugNoProguard when you wanted to run a debug build without ProGuard.

How to have multiple ApplicationIds for the same product flavor?

We have a white label application with a handful of flavors for different clients. A new client has come on that wants the ability to publish the app through their own developer account. However, prior to release, we need to test the app through our internal test track and verify that the prod environment works (such as billing).
When we got started with development, we created a new product flavor, "com.business.android.product". Now that we are getting close to release, we need a different package name, "com.example.android.thing". My question is, how can we have two package names for the same flavor (i.e. using the same code in the /product source folder)?
Here is an example of our flavor and build type setup
productFlavors {
prod1 {
applicationId "com.business.android"
buildConfigField 'boolean', 'REPORT_CRASHES', "true"
}
prod2 {
applicationId "com.business.android.product2"
buildConfigField 'boolean', 'REPORT_CRASHES', "true"
}
prod3 {
applicationId "com.business.android.product3"
buildConfigField 'boolean', 'REPORT_CRASHES', "true"
def flavor = "spg"
}
prod4 {
applicationId "com.company.android.product4"
buildConfigField 'boolean', 'REPORT_CRASHES', "true"
}
/* Need a way to have all the code in /prod4 flavor source folder but with
* a very different applicationId - ex. somebusiness.android.product4
*
*/
}
buildTypes {
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.KEY
def buildType = "debug"
def targetEnvironment = "production"
buildConfigField "boolean", "PRODUCTION_ENV", "true"
}
debugTst {
minifyEnabled false
debuggable true
signingConfig signingConfigs.KEY
def buildType = "debug"
buildConfigField "boolean", "PRODUCTION_ENV", "false"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.KEY
def buildType = "release"
buildConfigField "boolean", "PRODUCTION_ENV", "true"
}
releaseTst {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.KEY
def buildType = "release"
buildConfigField "boolean", "PRODUCTION_ENV", "false"
}
}
This issue can be resolved by performing the follow:
sourceSets {
prod4Ext.java.srcDirs += 'src/prod4/java'
prod4Ext.res.srcDirs += 'src/prod4/res'
}
This will provide the prod4 flavor's source code and layouts to the newly created flavor prod4Ext.

Assign different build types to different Flavors in android

In my Gradle file, I've assigned buildTypes and productFlavors in the following way.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
signingConfigs {
release{
//storeFile file("")
//storePassword ""
//keyAlias ""
//keyPassword ""
}
}
flavorDimensions "default"
productFlavors {
dev{
dimension "default"
applicationId "com.xxx.android.dev"
}
qa{
dimension "default"
applicationId "com.xxx.android.qa"
}
staging{
dimension "default"
applicationId "com.xxx.android.staging"
}
prod{
dimension "default"
applicationId "com.xxx.android.prod"
}
}
Now the problem is each flavors has the both build types which is release and debug , But I want to assign debug for build only so we cannot produce a release build when selecting debug variant. Any idea how to do it?
I managed to get it done by adding build targets. i didn't want to change any source codes for this . so no need to go with flavors
buildTypes {
qa {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'String', ‘BASE_URL', ‘"url“'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'String', ‘BASE_URL', ‘"url“'
}
debug {
buildConfigField 'String', ‘BASE_URL', ‘"url“'
}
}

Where is the apk for my new build variant?

I read the "Build System" section of the android docs: http://developer.android.com/sdk/installing/studio-build.html
So a build variant is composed of a product_flavor-build_type. I have this build.gradle:
buildTypes {
debug {
applicationIdSuffix '.debug'
debuggable true
minifyEnabled !skipProguard
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
zipAlignEnabled false
}
debugtest {
// unit tests
applicationIdSuffix '.test'
debuggable true
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
zipAlignEnabled false
}
release {
minifyEnabled true
shrinkResources true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
productFlavors {
internal {
applicationId "${project.applicationId}.internal"
buildConfigField 'boolean', 'EXPERIMENTAL', 'true'
buildConfigField 'boolean', 'FAKE_HTTP_RESPONSE', 'false'
}
production {
applicationId project.applicationId
buildConfigField 'boolean', 'EXPERIMENTAL', 'false'
buildConfigField 'boolean', 'FAKE_HTTP_RESPONSE', 'false'
}
automation {
applicationId "${project.applicationId}.automation"
buildConfigField 'boolean', 'EXPERIMENTAL', 'true'
buildConfigField 'boolean', 'FAKE_HTTP_RESPONSE', 'true'
}
}
I'd like to create mobile-debug-automation-unaligned.apk so that I can use the "FAKE_HTTP_RESPONSE" BuildConfig variable in a dagger module.
But when I click on "Build Variants" in Android Studio I see one build variant-"internalDebug". I expected to see 9 build variants(buildType * productFlavor).
Looking in my project directories, I see the following apks:
MY_APP/mobile: mobile-release.apk, mobile-debug-unaligned.apk
MY_APP/mobile/build/outputs/apk: mobile-internal-debug-unaligned.apk
How do I generate my new "automation" apk?
Plz click on it to change:
If it doesn't work, rebuild your project.

Categories

Resources