通过 Git 集线器秘密在 build.gradle android 中传递 local.properties
pass local.properties in build.gradle android through Git Hub secret
我正在尝试自动构建 android 应用程序的过程,我将 baseUrl 存储在 local.properties 文件中,并通过 Github 秘密传递文件内容,但是 Github行动一直失败,
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
我如何通过 Github 秘密
传递 BASEURL
这是 Github 操作控制台
的日志输出
我解决了我的问题,我从 Github secret 传递了错误的参数,它应该像
\"http://fakeapi.com"\
而且我在操作文件中做错了,而不是 ./gradlew build 它应该是
./gradlew assembleDebug --stacktrace
然后它只会从 build.gradle 调用下面的部分并用 local.properties
的新值替换 BaseUrl
debug {
buildConfigField 'String', "BASEURL", baseUrl
resValue 'string', "base_url", baseUrl
}
我还使用 https://github.com/juliangruber/read-file-action 查看了 local.properties 的内容并验证了此文件中的一切是否正常。
我正在尝试自动构建 android 应用程序的过程,我将 baseUrl 存储在 local.properties 文件中,并通过 Github 秘密传递文件内容,但是 Github行动一直失败,
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
我如何通过 Github 秘密
传递 BASEURL这是 Github 操作控制台
的日志输出我解决了我的问题,我从 Github secret 传递了错误的参数,它应该像
\"http://fakeapi.com"\
而且我在操作文件中做错了,而不是 ./gradlew build 它应该是
./gradlew assembleDebug --stacktrace
然后它只会从 build.gradle 调用下面的部分并用 local.properties
的新值替换 BaseUrldebug {
buildConfigField 'String', "BASEURL", baseUrl
resValue 'string', "base_url", baseUrl
}
我还使用 https://github.com/juliangruber/read-file-action 查看了 local.properties 的内容并验证了此文件中的一切是否正常。