pass local.properties in build.gradle android through Git Hub secret
Asked Answered
P

2

7

I am trying to automate build process of android app, I have stored baseUrl in local.properties file, and passing file content through Github secret, but Github action is keep failing,

build.gradle:

    def propFile=rootProject.file("./local.properties")
    def properties = new Properties()
    properties.load(new FileInputStream(propFile))

    def baseUrl = properties['BASEURL']
    //getProperty("BASEURL", "")


    debug {
        buildConfigField 'String', "BASEURL", baseUrl
        resValue 'string', "base_url", baseUrl
    }

YML:

name: Android CI

on:
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Decode BASEURL
      env:
        BASEURL: ${{ secrets.BASEURL }}
      run: echo BASEURL="$BASEURL" > ./local.properties


    - name: Clean
      run: ./gradlew clean
    - name: Build with Gradle
      run: ./gradlew build

How i am passing BASEURL through Github secret

enter image description here

This is log output from Github action Console

enter image description here

Pace answered 9/6, 2020 at 9:9 Comment(2)
You have probably placed local.properties not at the root of your project when you created it in github actions. Can you do echo BASEURL="$BASEURL" > ./local.properties, can you also run ls -al to see the layout of the filesScoundrel
i checked local.properties file is in root of the project, @ScoundrelPace
P
4

I solved my problem, I was passing wrongly argument from Github secret, it should be like

\"http://fakeapi.com"\

and also i was doing wrong in action file, instead of ./gradlew build it should be

./gradlew assembleDebug --stacktrace

then only it will invoke below part from build.gradle and replace the BaseUrl with new value from local.properties

debug {
            buildConfigField 'String', "BASEURL", baseUrl
            resValue 'string', "base_url", baseUrl
        }

I also used https://github.com/juliangruber/read-file-action to see the content of the local.properties and verified everything is fine in this file or not.

Pace answered 10/6, 2020 at 6:14 Comment(1)
it does seem to be like \"fakeapi.com\" ??? (please note the ' "\ ' in the answer).Tonneau
J
0

I used below command and its worked . Don't need to consider \

run: echo 'apiKey=${{ secrets.API_KEY }}' > ./local.properties

And secret key API_KEY value was stored like "*******"

Jacobjacoba answered 18/8, 2023 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.