Proper way to use System environment variables in gradle using Android Studio

前端 未结 2 1669
我在风中等你
我在风中等你 2021-01-01 10:36

I am using Android Studio to build my project on an Ubuntu 14.04 system.

I wrote the following in my build.gradle files to avoid hardcoding storeFile, storePassword,

2条回答
  •  清歌不尽
    2021-01-01 10:55

    Create a gradle.properties file in your source folder (alongside build.gradle) to apply only to the current project or in ~/.gradle/gradle.properties to apply system-wide with the contents:

    keystore=/home/myname/keystore/mykey
    keystore_password=mypass
    key_alias=mykey
    key_password=keypass
    

    Now update your build.gradle file with:

    debug {
      storeFile file("${keystore}")
      storePassword "${keystore_password}"
      keyAlias "${key_alias}"
      keyPassword "${key_password}"
    }
    

    Optionally, you could pass the parameters from command-line with the -P option. For example, ./gradlew assemble -Pkey_password=keypass.

提交回复
热议问题