I’m setting up a CI/CD pipeline for an Android project in GitHub. The app uses Google Maps API keys for three different environments. Currently, I store these keys in the local.properties file and access them in the app/build.gradle to inject them into the BuildConfig.
As part of the CI/CD process, I’ve moved the Google Maps API keys into GitHub’s repository secrets as environment variables. In the GitHub Actions workflow (build.yml), I’m setting these secrets as system environment variables to make them accessible during the build process, like this:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '22'
distribution: 'temurin'
cache: gradle
- name: Access DEV_GOOGLE_PLACES_API_KEY
env:
DEV_GOOGLE_PLACES_API_KEY: ${{ secrets.DEV_GOOGLE_PLACES_API_KEY }}
run: echo 'DEV_GOOGLE_PLACES_API_KEY=${{ secrets.DEV_GOOGLE_PLACES_API_KEY }}' >> $GITHUB_ENV
- name: Access STAGE_GOOGLE_PLACES_API_KEY
env:
STAGE_GOOGLE_PLACES_API_KEY: ${{ secrets.STAGE_GOOGLE_PLACES_API_KEY }}
run: echo 'STAGE_GOOGLE_PLACES_API_KEY=${{ secrets.STAGE_GOOGLE_PLACES_API_KEY }}' >> $GITHUB_ENV
- name: Access PROD_GOOGLE_PLACES_API_KEY
env:
PROD_GOOGLE_PLACES_API_KEY: ${{ secrets.PROD_GOOGLE_PLACES_API_KEY }}
run: echo 'PROD_GOOGLE_PLACES_API_KEY=${{ secrets.PROD_GOOGLE_PLACES_API_KEY }}' >> $GITHUB_ENV
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew buildwhiskeyDebug
Writing these values into Build.config in app/build.gradle file as follows:
buildTypes {
debug {
def devApiKey = System.getenv("DEV_GOOGLE_PLACES_API_KEY")
buildConfigField "String", "DEV_GOOGLE_PLACES_API_KEY", ""${devApiKey}""
}
release {
def devApiKey = System.getenv("DEV_GOOGLE_PLACES_API_KEY")
buildConfigField "String", "DEV_GOOGLE_PLACES_API_KEY", ""${devApiKey}""
}
}
But getting CI/CD build process is failing with error:
‘../android/web/BuildConfig.java:13: error: ‘;’ expected
public static final String DEV_GOOGLE_PLACES_API_KEY = “***”; ‘
‘../android/web/BuildConfig.java:13: error: expected
public static final String DEV_GOOGLE_PLACES_API_KEY = “***”; ‘
What am I missing here?