Flutter:構建 APK 時如何傳遞 Gradle 參數? (Flutter: how do I pass Gradle params when building an APK?)


問題描述

Flutter:構建 APK 時如何傳遞 Gradle 參數? (Flutter: how do I pass Gradle params when building an APK?)

在使用 Gradle 構建常規 Android 應用程序時,我可以這樣添加參數:

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

使用 Flutter,我應該調用它來組裝 APK:

flutter build apk

在這種情況下如何將參數傳遞給 Gradle?

PS 我正在嘗試在管道配置中使用 Jenkins 憑據。我不想暴露我的密碼,因此避免使用參數並將其直接放入項目中是不可行的。


參考解法

方法 1:

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.

方法 2:

You can set project properties through environment variables like ORG_GRADLE_PROJECT_foo=bar, so that you don't have to modify the gradle scripts, for example:

export ORG_GRADLE_PROJECT_username=foo 
export ORG_GRADLE_PROJECT_password=bar
flutter build apk

Docs: Project properties

(by Alex Timoninspacificixinthink)

參考文件

  1. Flutter: how do I pass Gradle params when building an APK? (CC BY‑SA 2.5/3.0/4.0)

#Android #Flutter






相關問題

檢索和解析 JSON (Retrieving and Parsing JSON)

Aplikasi Baru - Bangun SDK Android 2.2 (API 8) tidak tersedia. Bagaimana cara membuatnya muncul? (New App - Build SDK Android 2.2 (API 8) not available. How to make it show up?)

How to delete a row in Sqlite database in Android application by user at listview (How to delete a row in Sqlite database in Android application by user at listview)

在Android的整個佈局之上畫一條線? (Draw a line on top of entire layout in Android?)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

當有更大的屏幕時,觀看次數會增加 (when there is a bigger screen make views grow)

從Android應用程序中的較大圖片中提取和使用圖像縮略圖 (Extracting and using Image Thumbnail from larger picture in android app)

如何自動創建聯繫人? (How to create contact automatically?)

su -c 在 Android (Linux) 中給出“[1] Segmentation fault” (su -c gives "[1] Segmentation fault " in Android (Linux))

RelativeLayout wrap_content 問題 (RelativeLayout wrap_content problem)

在選擇一個視圖時顯示視圖 (Bring a view on selecting one view)

如何在蜂窩中的另一個對像後面發送動畫? (How can an animation be sent behind another object in honeycomb?)







留言討論