android - 使用 Actions 时将 build.gradle 中的 local.properties 与 Github Secrets 一起使用
问题描述
在使用 Github Actions 时,我试图用 Github Secrets 值替换位于 local.properties 中的 API 密钥。
键在 local.properties 中声明如下:
sdk.dir=/Users/xxxxxxx/Library/Android/sdk
API_KEY="xxxxxx"
然后,在我的 build.gradle 中,我得到这样的属性:
buildTypes {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def api = properties.getProperty('API_KEY')
debug {
buildConfigField 'String', "API_KEY", api
resValue('string', "api", api)
.....
然后运行 Github Actions 以在此处将值替换为秘密:
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.API_KEY }}
run: echo API_KEY="$API_KEY" > ./local.properties
- name: Assemble app debug APK
run: bash ./gradlew assembleDebug --stacktrace
- name: Unit tests
run: ./gradlew test
但是,每次运行此操作时,构建都会失败并出现以下错误:
- 出了什么问题:评估项目“:app”时出现问题。指定为非null的参数为null:方法com.android.build.gradle.internal.dsl.BuildType.resValue,参数值
它指向的行是 buildConfigField 'String', "API_KEY", api 行。
我在这里做错了什么?
解决方案
我认为你有一个错误:
MOCK_USERNAME: ${{ secrets.API_KEY }}
应该是这样的:
API_KEY: ${{ secrets.API_KEY }}
推荐阅读
- r - 从 colnames 子集日期
- bash - 为什么在我的 PS1 末尾添加 \n 会导致替换错误?
- kdb - 创建一个空表,从另一个表中获取列名
- linux - 需要用一个变量比较两个字符串
- java - 从recycleview解析Android Html
- javascript - 未捕获的 SyntaxError:无效的正则表达式:/@|#|$|&|*/:没有可重复的内容
- c++ - 12:00:01 AM 是有效时间吗?
- react-native - react-native:在 ubuntu 18.04 中找不到命令
- javascript - 我必须遍历多级 JSON 并删除某些键
- javascript - getText 和 getAttribute 为量角器中的输入字段获取空值