DEV Community

Cover image for Use GitHub secrets in your Android App
Sumanth Perambuduri
Sumanth Perambuduri

Posted on • Edited on

Use GitHub secrets in your Android App

Alright I am gonna get straight to the point.

  • Add 'app/src/main/res/values/secrets.xml' and 'app/src/main/res/values/secrets.xml~' in '.gitignore' file.
  • Create 'secrets.xml' file in 'app/src/main/res/values' path.
  • Add the following code in 'secrets.xml' :
    <resources>
    <string name="API_KEY">YOUR_KEY_HERE</string>
    </resources>
    view raw secrets.xml hosted with ❤ by GitHub
  • Add the following code to your 'activity.kt' file:
    val secret = getString(R.string.API_KEY)
    view raw main.kt hosted with ❤ by GitHub
  • Add the following code under steps in your workflow file rite before build step:
    - name: Access Api keys
    env:
    apiKey: ${{ secrets.API_KEY }}
    path: app/src/main/res/values/secrets.xml
    run: |
    touch $path
    echo \<resources\> >> $path
    echo \<string name=\"API_KEY\"\>$apiKey\</string\> >> $path
    echo \</resources\> >> $path
  • Finally, add the secret to your GitHub repository with key “API_KEY”.
  • That’s it. You are good to go.

Here's the example project:
Spotify Playlist Downloader

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more