【问题标题】:Gradle - Different configs for release and debug don't workGradle - 用于发布和调试的不同配置不起作用
【发布时间】:2018-03-29 08:42:05
【问题描述】:

我正在尝试将 Gradle 设置为具有不同的发布和调试版本设置。

用例:开发人员不需要签名文件和配置来构建调试版本。

但 gradle 拒绝同步/构建 debug 版本,因为缺少文件def keystorePropertiesFile = rootProject.file("keystore.properties") - 但这些设置仅用于发布构建。

我做错了什么?

...

android {

    ...
    defaultConfig {
        ...
    }
    buildTypes {
        release {
            ...
            signingConfigs {

                def keystorePropertiesFile = rootProject.file("keystore.properties")

                // Initialize a new Properties() object called keystoreProperties.
                def keystoreProperties = new Properties()

                // Load your keystore.properties file into the keystoreProperties object.
                keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']

            }
        }
        debug {
            ...
        }
    }
    ...
}
...

【问题讨论】:

标签: android gradle


【解决方案1】:

构建时会评估整个 gradle 文件。所以它会抛出错误。在调试的情况下,我认为 gradle 使用 android 调试密钥库自动签署 apk

评论签名以供发布

提供一个包含虚拟内容的属性文件,以便 gradle build 在调试时工作

【讨论】:

  • 那..有点令人不安。感谢您的帮助:) 为什么 gradle 会这样做?评估我目前不需要的设置有什么意义?
  • 它基本上是一个脚本,所以这就是为什么我认为它逐行评估/运行
【解决方案2】:

您总是可以在纯 Java 中进行一些检查,例如:

File keystorePropertiesFile = new File(distrDir, fileName)
  if (!keystorePropertiesFile.exists()) {
     println "DEBUG message, properties set not from production file"
     // throw new GradleException('Also you can interrupt everything')
  } else {
     println "Do your file loading here..."
 }

【讨论】:

    猜你喜欢
    • 2017-05-28
    • 2013-06-08
    • 2012-05-31
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 2015-02-01
    • 2011-06-02
    相关资源
    最近更新 更多