react-native-google-places icon indicating copy to clipboard operation
react-native-google-places copied to clipboard

Having two API Key for different configurations

Open MelanieJourne opened this issue 5 years ago • 2 comments

Hello,

Is there any possibilities to put the API Key outside the file "Gradle.properties" ?

I have a development config (productFlavors) and a production one and I would like to use two different API Key. However, I can not switch it each time I make an apk.

Ideally I would like to do something like this (either by manifest placeholder or by build config value):

productFlavors {
    beta {
        dimension 'env'
        applicationId "com.my.fake.package"
        signingConfig signingConfigs.release
        manifestPlaceholders=[google_api:"my-dev-api-key"]
    }
    prod {
        dimension 'env'
        applicationId "com.my.fake.package"
        signingConfig signingConfigs.release
        manifestPlaceholders=[google_api:"my-prod-api-key"]
    }
}

Can you please help me in how to proceed ?

Thanks

MelanieJourne avatar Jul 03 '19 14:07 MelanieJourne

Not sure about productFlavors but with buildTypes I use:

buildTypes {
  debug {
    resValue "string", "places_api_key", "AIza..."
  }
  release {
    resValue "string", "places_api_key", "AIza..."    
  }

jamesholcomb avatar Jul 13 '19 01:07 jamesholcomb

What I do is export it from android/gradlew which sources it from my .env file. I use react-native-config. See https://github.com/OurVoiceUSA/HelloVoter/commit/75ae7eded0b0cb70656ef837e04c58b85b89c299

cormander avatar Aug 02 '19 23:08 cormander