Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: how do I pass Gradle params when building an APK?

When building a regular Android app with Gradle, I can add params as such:

./gradlew assembleRelease -Pusername=foo -Ppassword=bar

With Flutter, this is what I'm supposed to call in order to assemble an APK:

flutter build apk

How do I pass the params to Gradle in this case?

P.S. I'm trying to use Jenkins credentials in a pipeline configuration. I do not want to expose my password, so avoiding using the arguments and putting it directly into the project is not an option.

like image 391
Alex Timonin Avatar asked Jan 10 '19 15:01

Alex Timonin


1 Answers

You can pass variables via the environment, I use this method with Jenkins. The job can be configured to pass the credentials via environment variables.

In your build.gradle (where needed):

username = System.getenv('SECRET_USERNAME')
password = System.getenv('SECRET_PASSWORD')

Please notice that System.getenv(...) returns null if the variable is not defined.

In your development environment you should export the variables:

$ export SECRET_USERNAME="my secret username"
$ export SECRET_PASSWORD="my super secret password"

Please, I do not know which IDE are you using, but both IntelliJ and AndroidStudio do support declaring environment variables.

like image 120
spacifici Avatar answered Nov 02 '22 01:11

spacifici