Drop us a line
CI/CD and want
to be featured
in our blog?
Mobile SDK: Continuous Integration for Mobile SDK with Nevercode
What’s a Mobile SDK?
As the popularity of mobile apps is growing, most companies and digital agencies need an architecture to build mobile apps faster. According to SmartInsights, 90% of mobile time is spent in apps – making the mobile app experience all the more important for both app developers and app users. Furthermore, study from Compuware finds that only 16% of users are willing to give a buggy app a second chance.
Therefore, in order to assure the quality and reuse existing code in multiple apps, companies started to build reusable software development kits (SDKs) and libraries so that the code can be easily reused in multiple apps.
SafeDK revealed in their SDKs market trend report that the average app has 18 SDKs, making SDKs irreplaceable parts of an effective and reliable platform to make it in the marketplace.
Why you Need CI/CD for your Mobile SDKs
As the library code can affect multiple clients, it’s essential to ensure that the code quality of the SDK meets the requirements of all clients. It’s also important to build a strong automated test suite in the SDK to make sure code changes for one client don’t affect others.
Getting quick and continuous feedback on the mobile SDK is very important. This is where the need for continuous integration comes into play. In most of the companies, there is a setup of CI/CD infrastructure for the main apps but none for the libraries and SDKs.
In reality, continuous integration for libraries and SDKs is very important, even more important than CI for the main apps.
In this post, we will explore how to set up CI/CD for libraries without any hassle using Nevercode.
How to Choose Mobile SDKs for your Needs?
There are millions of mobile SDKs available online, but building a great SDK isn’t a piece of cake. It requires effort and consideration of all the things that can affect clients who use the SDK. The ideal SDK should have some key features, like
- Simplicity and ease of use
- Great documentation
- Full test coverage
- Compatibility with the latest versions of tools
There is a great article about the best practices in mobile SDK development, you should read that if you want to explore more characteristics of a great mobile SDK.
If you ever wondered where to find an example of a great SDK, then have a look at those built by Apple. These SDKs are fully documented, easily integrated with IDE and can be used without any hassle. Apple is responsible for the code quality and documentation of those SDKs, so we can assume that those SDKs are of high quality.
However, if you want to build a SDK by yourself, then you should take care of all the code quality, testing and another important aspect of the SDK. There is a great collection of popular iOS SDKs written using Swift here, we could choose any SDK from there and set up continuous integration with Nevercode. We can also create a simple library HelloWorldKit which has an example app with unit and UI tests so that we can explore most of the SDK features:
- Source file
- Example app with unit and UI tests
We will see how we can add CI for HelloWorldKit with Nevercode without hassle.
Continuous Integration for HelloWorldKit SDK with Nevercode
Now that we have selected a candidate for continuous integration, let’s go on and add CI for HelloWorldKit library with Nevercode.
Add SDK to Nevercode
The next step is to select a branch, we will keep it as default and let Nevercode scan the project. In a couple of minutes, Nevercode will scan the repo and detect all the schemes and Xcode projects with default configuration. We can always change the schemes manually if we explicitly want to build, test other schemes from the Nevercode dropdown. We can also specify the branch patterns to be built for later code changes.
At this stage, once you are happy with the schemes and projects selection, click Save and start build which will trigger the build for our SDK. Nevercode will build and test the SDK. It will also generate artefacts for the build.
And that’s it! We have set up Continuous Integration for our SDK in just a couple of minutes. Yay!
Customizing CI/CD for mobile SDKs
We have now added basic CI setup for our SDK, but there are various other things we can do to make CI most robust and solid. Now, we will explore the features in order to build high-quality CI for our SDK.
With Nevercode, we can create workflows to cover different aspects of the SDK. A good example of this is running UI tests. As UI tests are time-consuming, it would be great to create a separate workflow for UI tests and run only unit tests with the default workflow. We can create a workflow by selecting Workflows in project settings and then duplicating the default workflow. Name the workflow as UI Test so that it will be visible in the dashboard.
It’s also possible to create a workflow for testing the SDK with old Xcode versions. Now, we will add another workflow to test the SDK with Xcode 9.3.1. We can switch the Xcode version in the Environment section.
This way, we can easily customise our workflows as per the project’s needs.
Enable Code Quality Check for SDK
There are more things we need to check to make sure we are building a high-quality SDK, like
- Running a linter to make sure there are no code styling issues
- Running all sorts of tests for SDK
- Ensuring there are no memory leaks or other kinds of problems
These things can be easily achieved on Nevercode simply by enabling code analysis, a native Nevercode feature. Static code analysis is available for iOS projects written in Objective-C and Android projects written in Java.
Now, let’s add these checks to our SDK build so that whenever we see these kind of problems, the build will fail. In Nevercode project settings, select Code analysis —> Enable this feature. Once you have enabled code analysis, you can select the options suitable for the SDK.
Now, Nevercode build will fail when there is any resource or memory leak. Nevercode will also check for code quality issues and generate a separate tab for code quality check. In the case of HelloWorldKit SDK, there are no issues observed.
Test SDK on Various Platforms
Similarly, testing is also painless on Nevercode as we can parallelise the tests by specifying the number of simulators and run them on the devices we want. In our example, we have just run them on iPhone XS Max simulator. As pointed out earlier, we can also change the Xcode version from the Environment tab in project settings.
Cache SDK Dependencies
There are various other beneficial features, like sending notifications or publishing the build to third-party services, but another key feature is adding caching for the builds. If we are building a SDK, then we might have used other dependencies, either with CocoaPods or Carthage. We need to cache these dependencies in order to speed up the builds. With Nevercode, we can enable this feature from the Caching setting. In the case of HelloWorldKit SDK, Nevercode already detected that caching is needed in the project, we just need to enable it.
Once caching is enabled, the subsequent build will use the cached dependencies to make the build execution faster.
Continuous integration for the libraries or the mobile SDK is as important as continuous integration for your mobile app. By adding strict continuous integration to mobile SDK, we can detect the problems earlier before they affect multiple clients. Continuous integration tools like Nevercode allow us to do that without any pain. We have seen how HelloWorldKit SDK is being checked for code quality on continuous integration server without doing a lot of scripting or configuration. You can check the build logs on Nevercode here for reference.
What is your experience with setting up CI for mobile SDK? Share in the comments below.
This article is written by Shashikant Jagtap.
Shashikant is DevOps practitioner for mobile apps and Director at XCTEQ Limited. He has automated release pipelines, implemented CI/CD and enabled DevOps cum Test Automation practices for many apps.
He blogs about mobile DevOps and CI/CD. Check-out XCTEQ for more: https://www.xcteq.co.uk/