Android: 启动进程“command 'gpg'”时出现问题,错误=2,没有那个文件或目录

Android: A problem occurred starting process 'command 'gpg'', error=2, No such file or directory

以问答的方式分享

问题陈述

我克隆了一个新项目,它有 gpg 加密。我在终端中通过 运行 brew install gnupg 安装了 gpg。我通过终端中的 运行 which gpg 命令确认了安装,它给了我 /opt/homebrew/bin/gpg 路径。我尝试构建该项目,但出现如下错误:

错误

A problem occurred evaluating script.
Build file '/Users/srdpatel/androidProjects/projectName/oneOfTheDirectoiesOutOfThreeSiblings/app/build.gradle' line: 10
A problem occurred evaluating script.
> A problem occurred starting process 'command 'gpg''
> A problem occurred starting process 'command 'gpg''
> org.gradle.api.GradleScriptException: A problem occurred evaluating script.
> Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'gpg'
> Caused by: java.io.IOException: Cannot run program "gpg" (in directory "/Users/srdpatel/androidProjects/projectName/oneOfTheDirectoriesOutOfThreeSiblings"): error=2, No such file or directory

应用级别Gradle第10行

apply from: '../credentials/crypto.gradle'

其他信息

  1. gpg 已经通过 brew install gnupg 安装并且仅更新了一个。
  2. 终端中的命令which gpg显示/opt/homebrew/bin/gpg.

问题出在脚本 apply from: '../credentials/crypto.gradle' 中。我们可以在 Android Studio 中按两次 shift 并输入 crypto.gradle 以转到该文件。在那里,我们可以找到 gpg 这个词。结果应如下所示:

def result = execute("gpg", ...

在这里,我们需要将 "gpg" 替换为我们从终端中的 which gpg 命令获得的绝对 gpg 路径。对我来说,它给了我:/opt/homebrew/bin/gpg。因此,我们需要编辑现有的 "gpg" 脚本,如下所示:

def result = execute("/opt/homebrew/bin/gpg", ...

现在,我们可以点击 Try again 来构建我们的 Android 项目,这一次,它应该不会抛出 A problem occurred starting process 'command 'gpg'', ... error=2, No such file or directory.