Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force to use same certificate to sign different "buildTypes" that are configured for a particular "productFlavor"?

Background:

I am generating builds using build variant. Below are the configurations:

signingConfigs {
    production {
        storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
        storePassword "somepassword"
        keyAlias "somekeyalias"
        keyPassword "some"
        v2SigningEnabled false
    }

    develop {
        storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
        storePassword "someother"
        keyAlias "someotherkeyalias"
        keyPassword "someother"
        v2SigningEnabled false
    }
}

productFlavors {
    production {
        signingConfig signingConfigs.production
      }

    develop {
        applicationIdSuffix ".develop"
        signingConfig signingConfigs.develop
     }
}

buildTypes {
    debug {
        minifyEnabled false
    }

    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

Problem

As, of now for example if I talk about flavour production then productionRelease uses signingConfigs.production to sign the apk. But, productionDebug doesn't uses signingConfigs.production.

Expected output

When I generate the signed apk I want the gradle to do the following for me:

  1. developRelease and developDebug should be signed with only signingConfigs.develop

  2. productionRelease and productionDebug should be signed with only signingConfigs.production

Another question that is similar to this which led me to do the above: SHA-1 different for buildTypes (debug and release) for same productFlavors Firebase?

like image 719
Anurag Singh Avatar asked Jul 18 '17 11:07

Anurag Singh


1 Answers

Remove the signingConfig signingCongigs.develop elsewhere in the code block

And add new property within the buildTypes like

  • withProduction
  • withDevelop

Now add signingConfig to it

Thereby your updated gradle file look like as below

signingConfigs {
    production {
        storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
        storePassword "somepassword"
        keyAlias "somekeyalias"
        keyPassword "some"
        v2SigningEnabled false
    }

    develop {
        storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
        storePassword "someother"
        keyAlias "someotherkeyalias"
        keyPassword "someother"
        v2SigningEnabled false
    }
}
productFlavors {
    production {
    }

    develop {
        applicationIdSuffix ".develop"
    }
}
buildTypes {
    /* NOTE: the debug block is not required because it is a default
 * buildType configuration; all of its settings are defined implicitly
 * by Gradle behind the scenes.
 */
    debug {
        minifyEnabled false
    }

    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.production
    }

    withProduction {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.production
    }

    withDevelop {
        minifyEnabled false
        signingConfig signingConfigs.develop
debuggable true

    }
}

In the terminal use the below gradle commmand: gradle assembleProduction to generate build with production certificates similarly gradle assembleDevelop or you can also use gradle assemble

You cannot force gradle to choose the certificates for debug property rather you could create own buildTypes

As per documentation

Automate signing your applications. Debug build variants are, by default, signed with a debug key for installation on development devices. Declare additional signing configurations for publication to the Google Play store.

Update: As the other answer pointed out,

Add debuggable true property under custom buildTypes against which you want to debug build and see the logs.

like image 67
Mani Avatar answered Oct 19 '22 14:10

Mani