Uploading Apps to TestFlight using Fastlane
We’ve all been there. We all know how frustrating it is when it comes to uploading our app to TestFlight. A lot of next and proceed buttons to tap till it successfully uploads to the TestFlight.
Using fastlane, we can skip all that hassles and can push our build to TestFlight with just one line of code i.e.
bundle exec fastlane beta
That would save u a lot of time in the long run. So, for the above code to work firstly we have to do some setup in our project. Let’s get on it then.
- There are multiple ways you can have fastlane installed in your system.We’ll install fastlane using Homebrew. Open Terminal and execute the following code:
brew install fastlane
Here’s the official link for setting up fastlane if you want to check it out.
2. After the process is completed, enter following command to check if fastlane has been installed in your system.
fastlane --version
3. Now, we’re done with the fastlane installation. Let’s setup fastlane in our project. Open Terminal in root directory of your project and run the following command.
fastlane init
Choose option 2 and hit Enter.
Then you’ll be asked for the apple id. Enter the apple id you use and hit Enter.
You might have two factor authentication enabled in your apple id and if you’re asked for code type ‘sms’ without quotes and hit enter. You’ll be provided with your phone number to select in which you’ll receive the code. Choose the phone number. Enter the received code and hit enter.
4. After you’ve successfully done the asked process in terminal go to your project from finder. You’ll see a new directory named fastlane there.
5. Go inside the fastlane folder. There’ll be two files named AppFile and FastFile.
6. If you open the AppFile, you’ll see the following contents:
Cross check if the values are correct.
7. Open up the FastFile. We are going to add some contents in it.
Inside lane :beta
we’ve added,
build_app(workspace: "fastlaneaddedproject.xcworkspace", scheme: "fastlaneaddedproject")
Replace fastlaneaddedproject.xcworkspace
with your project name and scheme with whatever scheme name you want to build if you have multiple schemes in your project.
The another linepilot( ipa: “fastlaneaddedproject.ipa”, skip_submission: true, skip_waiting_for_build_processing: true )
is responsible for uploading the ipa file generated by build_app
. Replace the fastlaneaddedproject.ipa
with your project name.
8. Now, we have to setup our certificates and profiles for the app. For this, we are going to use match which is a part of fastlane.
It basically helps us to create and manage our certificates and profiles without any headache. We will do it by,
a) For storing certificates and profiles we can use Git repo, Google Cloud or Amazon S3. We’ll be using Gitlab for this. Create a new project in Gitlab for storing certificates and profiles.
b) Execute a code in terminal to create a Matchfile.
fastlane match init
Edit the contents in Matchfile. Replace your_git_project_url.git with the url of the gitlab project you created to store certificates and profiles. Replace com.fastlaneaddedproject with your application bundle id. Finally, replace appleid@apple.com with your apple id. After editing has been done move the Matchfile inside the fastlane folder if it isn’t inside the folder.
9. Open your project in Xcode and navigate to Signing and Capabilities. If there is automatic signing enabled uncheck it and switch it to manual.
After switching to manual. it will look something like this.
We can see that there is showing None in Provisioning Profile. We need to have a profile i.e. Development, Adhoc or Appstore depending upon our need.
Quit your Xcode and to create those profiles we are going to run:
fastlane match development
then fastlane match adhoc
and finally fastlane match appstore
in root folder of our project. This will create the development and distribution certificates and profiles that we’ll need.
Then open your project and go to Signing and Capabilities and click on dropdown of Provisioning Profile. You’ll be able to select profile i.e. Development or Adhoc or Appstore if everything went smooth.
10. Now we’re all set. If you want to push a build to Testflight make sure your choose Appstore profile in Signing and Capabilities and run the command:
bundle exec fastlane beta
It’ll take > 6 minutes depending upon the size of your project. Now you won’t have to manually Archive the project then tap on Distribute and other things multiple times to upload your build to TestFlight. If everything went smooth everything will be done by fastlane and your build will be automatically uploaded in TestFlight.
If you want to see everything that is being done by fastlane type
bundle exec fastlane beta --verbose
which will print every ongoing process in terminal.
That’s it. We’ve successfully integrated fastlane in our project. Feel free to show your support.