4

We have a single package which is built for different sites, which needs some prebuild steps to be executed before actual build steps.

In flutter android, these steps are executed in "preBuild.dependsOn" (in android/app/build.gradle)

Edit (additional info):

MyFlutterMob/android/app/build.gradle

Following prebuild steps are run :

  def option = System.getenv('APK_FOR')

  setConfig()
  {
         if(option == "DEMO"){
             copy{
                 from "../../DemoAppAsset/AppLogo.png"
                 into "../../assets/images" 
             }
         }
         else if(option == "PROD"){
             copy{
                 from "../../ProdAppAsset/AppLogo.png"
                 into "../../assets/images" 
             }
         }
  }

  preBuild.dependsOn setConfig

Is same possible in flutter web build (Not able to find gradle script for same )

Gururaja Hegde
  • 323
  • 3
  • 9

2 Answers2

1

If you are using VSCode, I think you can set a prebuild in launch.json, as is explained here

Basically you can setup your .vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
        }
    ]
}

then, you should create a file tasks.json in the same folder, and add a script that will do what you want (for example a npm script)

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "copyClientConfiguration",
            "problemMatcher": []
        }
    ]
}

and lastly you can add this task as preLaunchTask in launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
            "preLaunchTask": "npm: copyClientConfiguration"
        }
    ]
}
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/29306541) – Lin Du Jul 01 '21 at 02:49
  • thanks @slideshowp2, I updated the answer – Guilherme Gabanelli Jul 01 '21 at 03:48
  • This wont work for building production package, Also how to pass parameter to select particular (PROD1/PROD2/UAT/... ) configuration is not clear – Gururaja Hegde Jul 08 '21 at 13:44
0

Wrote shall scrip which takes environment name(PROD1/PROD2/UAT/... ) as input and copies the required "images to white label" /"theme colour list files"/"strings list configs" into respective folders before running "flutter build web". Although it restricts all release to happen from linux / maintain equivalent bat file for windows, broadly it works out.

Gururaja Hegde
  • 323
  • 3
  • 9