生成 Gradle 包装文件时出错

Error when generate Gradle Wrapper files

我在 ubuntu 中有一个 React Native 项目,我想生成 Gradle 包装文件,所以我安装了 gradle,在 android/app 中我有 运行 这个命令

gradle wrapper --gradle-version 3.4.1

但是当我运行这个命令时,我得到了这个错误

FAILURE: Build failed with an exception.

* Where:
Build file '/var/MY_PROJECT/android/app/build.gradle' line: 122

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'release' for SigningConfig container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

我的问题发生是因为我调用了 SigningConfig 而没有定义它

所以我通过在/var/MY_PROJECT/android/app/build.gradle

中定义SigningConfig解决了这个问题
...
android {
  ...
  defaultConfig { ... }
  signingConfigs {
    release {
      if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
        storeFile file(MYAPP_RELEASE_STORE_FILE)
        storePassword MYAPP_RELEASE_STORE_PASSWORD
        keyAlias MYAPP_RELEASE_KEY_ALIAS
        keyPassword MYAPP_RELEASE_KEY_PASSWORD
      }
    }
  }
  buildTypes { ... }
}
...

if you want learn more about how to adding signing config to your app's gradle config click here