I have been trying to replace local.properties values via Github actions. There are a good few tutorials online, but I seem to be getting the same error each time.
I followed this: pass local.properties in build.gradle android through Git Hub secret
The issue is that I get the following error:
Parameter specified as non-null is null: method com.android.build.gradle.internal.dsl.BuildType.buildConfigField, parameter value
I attempted to get around this with an elvis operator like so:
buildTypes {
def propFile=rootProject.file("./local.properties")
def properties = new Properties()
properties.load(new FileInputStream(propFile))
def username = properties['MOCK_USERNAME']
def password = properties['MOCK_PASSWORD']
release {
buildConfigField 'String', "USERNAME", username ?: "\"foo\""
buildConfigField 'String', "PASSWORD", password ?: "\"foo\""
resValue('string', "mock_username", username ?: "\"foo\"")
resValue('string', "mock_password", password ?: "\"foo\"")
This succeeds but the value is always foo, rather than replaced by the actions yaml script:
on:
push:
jobs:
unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Update Username from Secrets
env:
MOCK_USERNAME: ${{ secrets.USER }}
run: echo MOCK_USERNAME="$MOCK_USERNAME" > ./local.properties
- name: Update Password from Secrets
env:
MOCK_PASSWORD: ${{ secrets.PASSWORD }}
run: echo MOCK_PASSWORD="$MOCK_PASSWORD" > ./local.properties
- name: Assemble app debug APK
run: bash ./gradlew assembleDebug --stacktrace
- name: Unit tests
run: ./gradlew test
In all of the tutorials I have seen, nobody has to use the elvis operator or gets the nullable error. I am not sure why this is happening. The project itself is multi-module (an SDK and a sample application) so I wonder if it is not referencing local properties correctly?
Any help here would be appreciated.