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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay