android - gradle属性中的正确配置键

标签 android gradle

我正在尝试使用 android studio 将我的 apk 直接上传到 playstore。

使用 ribot 样板我可以看到他们将 key 放在 gradle.properties 中,如下所示:

ribotAppKeystoreReleaseLocation = keystore/release.keystore
ribotAppReleaseKeyAlias = UNDEFINED
ribotAppReleaseStorePassword = UNDEFINED
ribotAppReleaseKeyPassword = UNDEFINED

并在构建 gradle 中:

    // You must set up an environment var before release signing
    // Run: export RIBOT_APP_KEY={password}
    release {
        storeFile file("${ribotAppKeystoreReleaseLocation}")
        keyAlias "${ribotAppReleaseKeyAlias}"
        storePassword "${ribotAppReleaseStorePassword}"
        keyPassword "${ribotAppReleaseKeyPassword}"
    }

如果我在 gradle.properties 中编写我的 key ,例如:

ribotAppReleaseStorePassword = THISISMYKEY

我将它上传到 git 时会遇到问题,因为所有团队都会看到这个 key 。 那么,我可以在这里设置系统环境变量吗?或者我应该怎么做?

See full boilerplate

最佳答案

Can I set the variables in the local file

当然:

apply plugin 'com.android.application'

def keystorePropertiesFile = file('keystore.properties')
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
  compileSdkVersion 26
  buildToolsVersion '26.0.1'

  defaultConfig {
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName '0.0.1'
  }

  signingConfigs {
    release {
      keyAlias keystoreProperties['keyAlias']
      keyPassword keystoreProperties['keyPassword']
      storeFile file(keystoreProperties['storeFile'])
      storePassword keystoreProperties['storePassword']
    }
  }

  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }
}

在这里,我有一个单独的 keystore.properties 文件,用于签名信息。然后,将 keystore.properties 放入 .gitignore

关于android - gradle属性中的正确配置键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45680769/

相关文章:

android - Gradle 构建在 Android Studio 中失败

android - 我无法将 Compose 从 1.1.1 升级到 1.2.0

java - 同时按下 2 个或更多键

android - C 源代码不会为 ARM 架构编译

android - android `isConnected()`中 `isAvailable()`和 `NetworkInfo`的区别

gradle - java.rmi.UnmarshalException : Error unmarshaling return header;

android-studio - Gradle依赖错误

android - 尝试在现有的flutter应用中实现flutter_contacts示例

android - 在 Android 中查找当前位置的天气更新的最佳方法

android - 尝试添加库,但使用 Gradlew Clean : Build Fails in Android Studio