6

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

Jitendra Prajapati
  • 1,002
  • 1
  • 10
  • 33
  • 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 files – smac89 Jun 09 '20 at 17:24
  • i checked local.properties file is in root of the project, @smac89 – Jitendra Prajapati Jun 10 '20 at 04:59

2 Answers2

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.

Jitendra Prajapati
  • 1,002
  • 1
  • 10
  • 33
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 "*******"

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50