Skip to content

Instantly share code, notes, and snippets.

@JakeSteam
Last active March 23, 2024 19:24
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeSteam/4ff98553691d1d30949fb1de6adf83a5 to your computer and use it in GitHub Desktop.
Save JakeSteam/4ff98553691d1d30949fb1de6adf83a5 to your computer and use it in GitHub Desktop.
Accessing Android app secrets from GitHub Actions using Gradle (https://blog.jakelee.co.uk/accessing-android-app-secret-from-github-actions-using-gradle/)
android {
....
defaultConfig {
....
buildConfigField ("String", "AUTH_CODE", getApiKey())
}
}
String getApiKey() {
def propFile = rootProject.file("./local.properties")
def properties = new Properties()
properties.load(new FileInputStream(propFile))
return properties['APOD_API_KEY']
}
dependencies {
....
}
name: CI
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Access APOD_API_KEY
env:
APOD_API_KEY: ${{ secrets.APOD_API_KEY }}
run: echo APOD_API_KEY=\"$APOD_API_KEY\" > ./local.properties
- name: Build the app
run: ./gradlew assembleDebug
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C\:\\Users\\Jake\\AppData\\Local\\Android\\sdk
APOD_API_KEY="abcd1234"
package uk.co.jakelee.apodwallpaper.example
import uk.co.jakelee.apodwallpaper.BuildConfig
class MyClass() {
val key = BuildConfig.APOD_API_KEY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment