我正在嘗試在 Android Studio 中運行 Flutter 應用程式,但在此之前,我需要將一些檔案從一個目錄復制到另一個目錄。所以我創建了以下copy_webenv.cmdWindows 腳本:
xcopy webenv\%1 web\ /E/Y
然后我在 Android Studio 中創建了一個 Shell 腳本構建配置,它使用一個dev引數運行這個腳本:

當我自己運行這個構建配置時,它可以完美運行:
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\sarbogast\dev\buzzwordbingo>C:\Users\sarbogast\dev\buzzwordbingo\copy_webenv.cmd dev
C:\Users\sarbogast\dev\buzzwordbingo>xcopy webenv\dev web\ /E/Y
webenv\dev\favicon.png
webenv\dev\index.html
webenv\dev\icons\Icon-192.png
webenv\dev\icons\Icon-512.png
4 File(s) copied
但是當我嘗試將此構建配置添加到我的 Flutter 構建配置的“啟動前”步驟時:

并運行此構建配置,我收到以下錯誤:

Error running 'copy webenv dev'
Executable is not specified
我在任何地方都看不到任何可執行欄位。
uj5u.com熱心網友回復:
看起來這是android studio中的一個錯誤。要解決此問題,您可以改用 gradle 任務或使用外部工具。
沒有 Gradle 任務
如果您不能為您的用例使用 gradle 任務,那么您可以在Run External tool選項中使用該Before Launch選項。
.
然后在工具配置中,您可以僅用cmd作程式和/c copy_webenv.cmd dev引數。

使用 Gradle 任務
如果您可以使用 gradle 任務,那么您需要將其添加到您的build.gradle:
task runCopyScript(type: Exec) {
commandLine 'cmd', '/c', 'copy_webenv.cmd', 'dev'
}
然后當gradle同步后,你可以在android studio的編輯器中點擊它旁邊的播放按鈕來運行它,這樣它就被添加為一個運行配置。
And then you can add that configuration as a "Before Launch".
Some side notes:
- It would actually be better to use a gradle copy task for this. In that way, it will immediately be platform agnostic and gradle could also optimize.
- It would actually be better to hook this in the the build system with gradle as shown in this answer. That way it will be more easy for other people checking out the project the first time and will also simplify stuff for building with some CI system.
- You could probably also use build variants
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/348582.html
