Flutter build app TeamCity config

Template build configuration to build a flutter app with TeamCity

Thu, 22 Jun 2023

This is a template for TeamCity to build a flutter application. To date I have tested this with 2 different apps on Android and iOS.

  1. Go to root project
  2. scroll down and click create template under “Build Configuration Templates”
  3. Under general settings we want to make the 2 adjustments. The first one is to change the build number. I use semver to create build numbers. The generated build number will be used in the deployment script in a later post. The second change is to add the artifact paths from our build. The below line will set our build numbers to 0.1.0.5 for example. The 5 will increment with each build by one

    Set Build number format to: %version_name%.%build.counter% Set Artifact paths to

    %system.teamcity.build.workingDir%/build/app/outputs/bundle/release/*.aab => .
    %system.teamcity.build.workingDir%/build/ios/ipa/*.ipa => .
    %system.teamcity.build.workingDir%/build/ios/ipa/*.dSYM.zip => .

    The .aab file is the android app bundle file thats produced with android builds and the .ipa is the iOS app file and the .dSYM is for debugging purposes. You don’t have to use the .dSYM file but I do for my crashlytics reports. I will show you how to upload it in a future post

  4. Under Version Control Settings I like to only do deployments for my main branch and pull requests. If you want to do the same set the Branch Filter to
+:<default>
+:refs/pull/*/merge
  1. I use fastlane for all of my build steps. This is what my lane looks like for ios.
  lane :build do |options|
	# Before calling match, we make sure all our devices are registered on the Apple Developer Portal
	register_devices(
	  devices: {
		"Eddie Detective" => "00008101-001459D02629001E"
	  }
	)

	# After registering the new devices, we'll make sure to update the provisioning profile if necessary
	sync_code_signing(force_for_new_devices: true, type: "adhoc")

	# Getting flutter dependencies
	sh("flutter", "pub", "get")

	# Installing pods
	cocoapods(deployment: true)

	# Building with Flutter
	build_app(workspace: "Runner.xcworkspace", scheme: "Runner", output_directory: "../build/ios/ipa")
  end

Here is the lane for Android

  lane :build do |options|
	# Building with Flutter
	sh("flutter", "build", "appbundle", "--build-number", options[:build_number], "--build-name=" + options[:build_name], "--no-pub")
end
  1. Next up is the build steps. Under Build Steps add 2. The first is Build iOS. Because this is a template I want this step to be optional. Under Add Condition add a new condition. The condition will be build_ios and set this to equals true. Set the Working Directory to ios and the custom script will just be fastlane build
  2. The second step is Build Android. You want to do the same thing except make the conditional parameter build_android and set the working directory to android. For the script section put this in there. This will build your android app and override the build version and number
bundler exec fastlane build build_name:%version_name% build_number:%build.counter%
  1. Under VCS triggers, just add the default trigger. If you specified the branch filter from the earlier step then setting the default trigger to * will only build on the default and pull request branches
  2. This step is optional but I do like to add the commit status publisher feature. You can add that in build features
  3. Under the Parameters section make sure your parameters look like this

parameters

  1. You can now create a new build configuration based on this template. It will ask you to supply the build_ios, build_android and version_name parameters. One thing to note, I manually update the version_name parameter when I’m changing my minor, major and patch versions
Buy Me A CoffeeDigitalOcean Referral Badge
Loading...
Edward Beazer

Edward Beazer - I just like to build shit. Sometimes I get stuck for hours, even days while trying to figure out how to solve an issue or implement a new feature. Hope my tips and tutorials can save you some time.

DigitalOcean Referral Badge