I am trying to run a Flutter app in Android Studio but before, I need to copy some files from one directory to another. So I created the following copy_webenv.cmd
Windows script:
xcopy webenv\%1 web\ /E/Y
Then I created a Shell Script build configuration in Android Studio that runs this script with a dev
parameter:
And when I run this build configuration on its own, it works flawlessly:
(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
But then when I try to add this build configuration to the "Before launch" steps of my Flutter build configuration:
And run this build configuration, I get the following error:
Error running 'copy webenv dev'
Executable is not specified
I don't see any executable field anywhere.
CodePudding user response:
Looks like that is a bug in android studio. To work around it, you could use a gradle task instead or use an external tool.
Without Gradle task
If you cannot use a gradle task for your usecase, then you could use the Run External tool
option instead in the Before Launch
options.
Then in the tool config you can just use cmd
as the Program and /c copy_webenv.cmd dev
as the Arguments.
With Gradle Task
If you can work with a gradle task then you would need to add this to your build.gradle
:
task runCopyScript(type: Exec) {
commandLine 'cmd', '/c', 'copy_webenv.cmd', 'dev'
}
Then when gradle is synced, you can click on the play button next to it in the editor in android studio to run it so that it is added as a run configuration.
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