In this article, we will see how to build a
flutter app for IOS using codemagic without a mac
Step 1: Generating the codesign signatures using OpenSSL
Download the binaries for OpenSSL. I got them
from here .Extract it to say C:/OpenSSL,
you can find the openssl.exe inside the bin folder. To make life easier, you
can add this path (;C:/OpenSSL/bin) to the "path" environment
variable, this allows you to call openssl command from anywhere. You should
also create a new Environment variable called “OPENSSL_CONF” and set its value
to the configuration file (in my case it is, C:\OpenSSL\bin\openssl.cnf).
Now that the initial setup is taken care of,
open powershell or a command prompt window. CD to the folder where you will be
storing your keys. First we need a private key using which we will generate a
certificate sign request file. To generate the private key, run the following
command
openssl genrsa -out iosKey.key 2048
The 2048 bit long key will be saved to a file
iosKey.key. Now to generate the csr
openssl req -new -key iosKey.key -out CertificateSigningRequest.certSigningRequest -subj "/emailAddress=email@domain.com, CN=spr, C=IN"
Now the
CertificateSigningRequest.certSigningRequest will be generated with the
request. Make sure that you change the email address, company name and country
code to your needs. You may also set default values in the openssl.cnf file.
Next go to, https://developer.apple.com/ login
and click "Certificates, Ids and Profiles". Click certificates and
then click the Plus sign near the heading that says Certificates.
- select iOS Distribution (App Store and Ad Hoc) or Apple Distribution as per your need. Click continue
- click on choose file and select the CertificateSigningRequest.certSigningRequest file we created earlier and click continue
- The signing certificate would be generated and click Download and save to the folder containing the iosKey.key file
Next step would be to create a pem file. Run
the following command
openssl x509 -in distribution.cer -inform DER -out ios_distribution.pem -outform PEM
Where distribution.cer is the name of the
certificate you downloaded from the apple developer site. Next we will generate
the p12 file (which is required by codemagic)
openssl pkcs12 -export -inkey iosKey.key -in ios_distribution.pem -out ios_distribution.p12
It will ask for a password, enter a password
and note it down in case you forget.
Step 2: Add the identifiers
On the apple developer page. Click on
"Identifiers" and then click the Plus sign near the heading that says
Identifiers, select “App IDs” and continue. Enter the name of your app in
Description and your apps Bundle ID in the respective field. Click Continue.
Make sure the bundle Id match with your apps bundle ID in
"\ ios\ Runner.xcodeproj\ project.pbxproj".
Step 3: Add test Devices (optional)
On the apple developer page. Click on
"Devices" and then click the Plus sign near the heading that says
Devices, Give a name to the device so that you can identify it. And enter the
UDID of the device. Click Continue and register. Repeat for all devices you may
want to distribute the app.
Step 4: Add distribution profiles
On the apple developer page. Click on
"Profiles" and then click the Plus sign near the heading that says
Profiles, Since we generated the sign key for Distribution. Select an option
under “Distribution”, I will be using
"Ad Hoc" so choose it and click continue.
- Under App ID select the name you created for Step2 and click continue.
- In the next step select the key you created previously in Step1 and click continue
- In the Select Devices step select all the devices you want to install the app on. (Probably the ones created in Step3). Click continue
- Enter a name for your profile under Provisioning Profile Name. Click Generate and Download the mobileprovision file
Note: You can generate multiple provisions for
the same app. Maybe an 'App Store' provision in addition to the 'Ad Hoc'
provision
Step 5: Configuring codemagic
- Expand Build, Set the necessary version for Flutter and Xcode. Under 'Build for platforms' uncheck the platforms you don’t need and change the Mode to release. Click save
- Expand Publish,
- Under 'iOS code signing' choose Manual.
- Under 'Code signing certificate' click choose a file and browse and select the .p12 file we created in Step1
- Enter the password you had given to the file in the 'Certificate password' field
- Under 'Provisioning profiles' upload the Profiles you generated in Step4. Save it
Click on 'Start new build'
Step 6: Distributing the app
Once the build finishes you will get an email
with the .ipa file and a .app file. You can upload the .ipa file to sites like
diawi and share the link with users whose mobile numbers are
registered in the app.
Limitations
- By moving away from mac. We lose the ability to use the Xcode simulator. So we can only test the app after a user/test-user installs it in a real device. A workaround can be seen here
- Since we are building on codemagic. We can't use custom edited packages. ie., in case we had manually edited a package in our local environment those changes can't be expected in the codemagic build since it will fetch from the original package repository. A workaround can be seen here
In the next article we will see how to build
an app for ios using codemagic, if a key was already generated in mac.
No comments:
Post a Comment