3

I'm trying to set up my Android project so that I can have 3 different versions of it working in parallel, pointing to different backend APIs and so on:

  • A debug/dev version that I only use for my own development
  • A beta/qa version that I release internally to my customer so that they can test the app without messing with the production environment
  • A production version that is released to the Play Store for everyone to use

As I said, the 3 versions should be installable in parallel on the same device (so I guess they should have different application ids), with different icons, point to different backend APIs and so on.

For that, I figured the best option would be to use product flavors like so:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "env"
    productFlavors {
        dev {
            dimension "env"
            applicationId "com.myapp.dev"
            resValue 'string', 'backend_url', 'https://dev.example.com'
        }
        beta {
            dimension "env"
            applicationId "com.myapp.beta"
            resValue 'string', 'backend_url', 'https://beta.example.com'
        }
        prod {
            dimension "env"
            applicationId "com.myapp"
            resValue 'string', 'backend_url', 'https://www.example.com'
        }
    }
}

And I created the corresponding dev, beta and prod directories under src, to have separate resources there, like the launcher icon for each flavor for example.

Now I would like to integrate Google Maps into my app. So I created a Google Maps Activity and Android studio came up with 2 google_maps_api.xml that he put in the debug and release subdirectories in src. If I'm not mistaken, those configuration files should be flavor-specific instead of buildType-specific, so I moved the one from debug into dev, I moved the one from release into beta and I copied the one from beta into prod. So now I have the following file structure:

Project file structure

So now I'm getting to the point where I need to generate Google Maps API keys for each flavor and restrict them to each flavor of my app. But in order to do that, I need to specify the SHA-1 fingerprint in each Google Cloud Project's API key. And I'm not sure which one to use there. Can I just use the same SHA-1 fingerprint for all of them? Am I supposed to have a different SHA-1 fingerprint for each build type (debug/release) or for each flavor (dev/qa/prod)? If so, how do I find the right fingerprint to use for each key?

Note that I tried the Gradle signing report, but it didn't help much:

13:05:37: Executing task 'signingReport'...

Executing tasks: [signingReport]


> Task :app:signingReport
Variant: prodDebug
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: devRelease
Config: none
----------
Variant: prodRelease
Config: none
----------
Variant: betaRelease
Config: none
----------
Variant: prodReleaseUnitTest
Config: none
----------
Variant: betaDebugAndroidTest
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: devReleaseUnitTest
Config: none
----------
Variant: prodDebugUnitTest
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: devDebugUnitTest
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: devDebugAndroidTest
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: betaDebugUnitTest
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: devDebug
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: betaReleaseUnitTest
Config: none
----------
Variant: prodDebugAndroidTest
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------
Variant: betaDebug
Config: debug
Store: /Users/sarbogast/.android/debug.keystore
Alias: AndroidDebugKey
MD5: 93:AA:D5:1B:0D:EA:7B:49:0B:BE:9F:13:FA:46:74:3F
SHA1: 09:FE:D6:BF:19:44:FC:BB:AB:7E:24:19:F7:A9:7D:31:2B:A5:55:17
SHA-256: 62:99:B8:38:07:B1:41:63:62:39:1B:2F:8A:80:F4:F6:E6:A5:97:2C:D0:7B:28:1E:34:2F:90:D1:10:C3:04:C4
Valid until: Monday, November 9, 2043
----------

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
13:05:38: Task execution finished 'signingReport'.

I'm still relatively new to this whole Android ecosystem and I couldn't find a lot of documentation about this kind of setup, so I'm not sure I'm doing the right thing either.

Sebastien
  • 3,583
  • 4
  • 43
  • 82

2 Answers2

1

May be problem in your signingConfig

Try this,

signingConfigs {
    productname{
        storeFile file("release.keystore") //or jKs file path
        storePassword "myPassword"
        keyAlias "myAlias"
        keyPassword "Something...."
    }
}

buildTypes {

    debug {
        signingConfig signingConfigs.productname
    }
    release {
        signingConfig signingConfigs.productname
    }
}
Ganesh Pokale
  • 1,538
  • 1
  • 14
  • 28
0

Since you have 3 different Google Cloud Projects I believe you will need 3 different SHA-1 fingerprints one for each of your flavors, since you have 3 different google_maps_api.xml files.

If I am not mistaken, on each of the google_maps_api.xml a different SHA-1 key should be present there.

Chagall
  • 282
  • 3
  • 12