In the development world, it’s very common for technologies to be rapidly updated to introduce new features that improve the development experience and performance. These updates are very beneficial for developers because they allow them to create better products. This is especially the case when a CI/CD like Codemagic is used for continuous deployment that streamlines the process of delivering new products. But things aren’t always rosy — have you ever wondered what problems can arise when technologies are updated quickly and the version you use locally is not the same as the one you have configured in Codemagic?
In the following article, we will explain in detail why versions are updated, why your build works locally but not in Codemagic CI/CD, and much more.
This article is written by Felipe Vergara
Why do the versions change?
First of all, we must be clear about the concept of versions. This has to do with the practice of version control, which is used to manage the various changes that are made to the elements of a product or a configuration. A product’s version is the state the product is in at a given moment of its development or modification.
Therefore, versions are constantly changing for different reasons. Some changes may have been made to solve operating problems (bugs) or to incorporate new functionalities that improve the product, for example.
Preventive actions before a compilation in Codemagic
There are different actions you can take before performing a compilation in Codemagic to reduce potential errors and thus optimize resources.
After finishing a new change to your project, you’ll likely need to generate a new version of the product. This is why we recommend generating a version of the product locally before compiling it in Codemagic.
The following image shows the successful generation of an Android APK. It gives us some level of security to know that we managed to generate this APK locally.
After the compilation is successful, we must go to Codemagic to verify that all local configurations are also defined in the Codemagic settings.
If the local compilation fails, we must solve any problems locally before performing a compilation in Codemagic.
Why does something work on the local machine and not on the CI?
Has the build of a version ever worked correctly on your local machine, only to fail when you run it on Codemagic CI? This can be due to a number of different factors. Below, I’ll go over some common errors:
“Because name_of_project requires SDK version >= 2.x.x < 3.x.x, version solving failed.”
Perhaps you have encountered this error when running your CI in Codemagic. This issue occurs due to a version inconsistency. Let’s analyze the error step by step and go over how to solve it.
The first thing to pay attention to is the SDK version of the Flutter project that we are using locally. To retrieve this information, we must use the following command in a terminal (console):
This will return the information of the locally installed and used Flutter SDK.
Once we have this information, we know that the version of Flutter is 2.5.3. Then, we must go to our application in codemagic.io and enter in the settings of our application. Here, we must verify which version of Flutter is being used for the compilation:
As we can see in the Build section, the selected Flutter version is 1.26.0-17.4.pre, which doesn’t match the version we use locally; to solve this problem, we must change the Codemagic version to 2.5.3.
Save the changes and run the compilation once again.
“Found ‘Xcode 11.x, build version 11x’. Xcode 12.x or greater is required to develop for iOS.”
The following error is related to Xcode, which is the IDE used to develop iOS applications and their configurations. This error occurs because the version of Xcode that was used in the project is higher than the version that uses Codemagic configurations.
To find out the version of Xcode that is being used locally, we must run the following command in our terminal (console):
This command will give us more details about the version:
As we can see, the version of Xcode being used locally is 13.2.1. Now, we must verify which version of Xcode is being used in Codemagic.
The Xcode version being used in Codemagic is 11.0, so there is an inconsistency in the version. To solve this, we just have to change this version to the one we use locally and re-compile the application.
“Minimum supported Gradle version is 6.5. Current version is 6.1.”
This error occurs because the minimal version of gradle supported by the compiler is 6.5 and we, in our local project, are using a version lower than this one; to check the version of gradle we are using we must go to Android/gradle/wrapper/gradle-wrapper.propierties (see image below).
We must modify line 6: distributionUrl and replace the current version with the new one, which, as stated in the error message, must be higher than 6.5. To find out which is the correct address, you can find the Gradle versions here:
Then we upload the changes to our repository and re-compile, and our application build should work without problems.
The majority of the Flutter Android builds recently failed due to the misconfiguration of the Gradle. The issues with being unable to lint, using Flutter with other SDKs, and wrong classpaths are the most common in the Flutter GitHub issue list.
In general, if your application compiles correctly on your local machine and doesn’t work on Codemagic CI, the first thing you should try is to verify that the versions match on the CI and locally. And as we mentioned before, it’s important to take preventive action — you should always verify that the local operation is optimal before running a compilation in Codemagic.
Useful links and references
Felipe Vergara is a software engineer who has more than 5 years of experience in web and mobile development. In his free times he likes to share his knowledge to help the third party developers. You can find Felipe from Twitter, LinkedIn and Medium..