Trayson Keli'i
Trayson Keli'i

Reputation: 378

Gradle property as a string?

I am trying to set up ENV vars in my Android application (e.g. API keys for different environments). The command in our CICD that builds the apk file is found below (it can be release or debug but for the example below I am using debug)

gradlew assembleDebug

This works just fine, but now throughout the code I am using variables similar to the code snippet below:

private static final String API_KEY = BuildConfig.apiKey;

The idea is that the BuildConfig property apiKey would be replaced with different API keys based off of the env. My thought was to set the properties through the following command:

gradlew assembleDebug -PapiKey=SOME_STRING_API_KEY_VALUE

This does assign apiKey to the value SOME_STRING_API_KEY_VALUE but as a variable and not a string. I just want the string value. I feel there is some aspect of gradle/groovy that I am not understanding but what I want to accomplish seems pretty trivial.

Upvotes: 0

Views: 831

Answers (1)

Trayson Keli'i
Trayson Keli'i

Reputation: 378

Sorry for the inconvenience I should have done a little more research. I just had to use the escape characters for the API key values -PapiKey=\“SOME_STRING_API_KEY_VALUE\” if there is a more elegant solution to what I am trying to accomplish please let me know!

Upvotes: 1

Related Questions