Device SDK Size & Minification
Library size is an often misunderstood topic; adding in Bitcode, universal binaries, release mode optimization, app thinning, and compression does not make it any easier. This guide discusses the topic of SDK Size and explains how you can optimize the size of your App.
Introduction
FaceTec provides Device SDKs that integrate quickly and with minimal coding required into your Browser, Mobile Browser, iOS, or Android Apps. The FaceTec Device SDKs ship with a real-time image processing, computer vision, and machine learning pipeline, as well as machine learning models that do quality, security, and pre-Liveness checks.
Machine learning models tend to be large, but we have worked diligently to reduce the space required for the FaceTec SDK by App thinning, package size, and binary size reduction. The Device SDKs contain the bare necessities to do their job, and everything else resides on the far more resource-rich FaceTec Server.
To be very clear, if you learn nothing else from this document, no matter what you see on an App store listing for a Demo App, or in a FaceTec Sample App, please remember:
FaceTec Device SDKs add ~3.9MB (v9) and ~5MB (v10) to your iOS/Android Apps or Webpages (both compressed).
Demo
Here is a video that demonstrates the full process of verifying for yourself that an app that includes the FaceTec Device SDK adds ~3.9MB (v9) and ~5MB (v10) to your app: View Video.
This video shows you how to perform the entire process of distributing a thinned-for-arm64 iOS app:
- Downloading the FaceTec Device SDK (iOS) from scratch.
- Archiving the Complete Sample App.
- Choosing an arm64 device during App Thinning.
- Building an IPA file.
- Unzipping the IPA file and navigating to the primary FaceTec resource container.
- Zipping this resource by itself and verifying the size.
Please note: If you don’t perform thinning as in the above example, you will generate a "fat" (also called universal) app/package that will include the binaries and resources for both armv7 and arm64.
What is App Thinning (iOS/Android)?
iOS and Android have various ways of conveying a very similar concept. On both architectures, we define the concept of App Thinning as: "Creating and distributing your application so that your users only download the bytes they need over the wire, not bytes for an architecture that any given User’s phone does not support and does not use."
Architectures
There are 3 primary architectures:
- armv7 -- Old iPhones and Old Android devices.
- arm64 -- All new iPhones and most new Android devices.
- x86 -- iOS, Android Simulator, and an extremely small and dying segment of real Android devices.
The ~3.9MB (v9) and ~5MB (v10) quoted above is the size of the amount that our binary and resources add to the App your arm64 users get if you configure your App correctly. The size is less for armv7, as the binaries are inherently smaller.
Android
On Android, the concept is actually called "App Bundle".
https://developer.android.com/guide/app-bundle
"An Android App Bundle is a new upload format that includes all your App’s compiled code and resources, but defers APK generation and signing to Google Play."
Per the guide above, if you correctly apply App Bundles, your customers will download APKs that Google Play generates that ONLY contain the resources (at the specific resolution for that device) and binaries (specific libraries for that specific phone’s architecture).
App Configuration Options That You Control
When customers say they cannot add 4-5MB to their App because it’s already too big, FaceTec will usually go analyze their App and find a lot of bloat... Reasons for this include:
- Creating a fat/universal IPA/APK -- You can reduce your size by ~50% if you do proper thinning/bundling.
- Using Swift -- Adds 3-12MB to the App size simply by using Swift.
- Image resources -- We frequently see 10-30MB worth of images in Apps. Usually, these images are in unused flows in the App, or are only used once, or are not properly thinned -- and thus are punishing all users to provide high-resolution images to a few. Please consider:
- Applying App Bundling
- Dynamic resource download, where possible, instead of carrying around image data in your package.
- Applying image optimization to get a vast reduction in size with hardly noticeable changes to the actual image data itself.
Enable GZIP Compression on Web Server
All modern browsers support and automatically negotiate gzip compression for all HTTP requests. Enabling gzip compression on your web server can reduce the size of the transferred response by up to 90%, which can significantly reduce the amount of time to download the resource, reduce data usage for the client, and improve the time to first render of your pages.
FAQs
Q: "I downloaded your iOS SDK, and the size of the .framework file is 100+ MB. Does this mean this adds 100+ MB to my App?"
A: No, to get the size that FaceTec SDKs will add to your Application, you need to build an actual IPA file in release mode and apply proper thinning to see the true size. View Video.
Q: "I am seeing that FaceTec's App Store/Google Play demo App is 10, 20, 30, etc. megabytes. Does this mean the SDK is that big?"
A: Our App Store/Google Play demo App contains extra code and libraries in the container App, image resources, other resources, and may contain a version of FaceTec SDKs that is not exactly in line with our latest released version of FaceTec SDKs. Although we ensure our public demos do have a minimum quality bar, they could contain test code or experiments that affect the size. The only way to prove to yourself that the FaceTec SDK increases your iOS/Android App by ~3.9MB (v9) and ~5MB (v10) is to build your own App with FaceTec integrated and properly thinned. If you need assistance proving this to yourself and/or ensuring your App is properly thinned, please contact us with the exact steps you are taking to create a release package of your App, and the sizes of the various components you are seeing before and after thinning, and we can help you with this process.
Q: "Can we just use certain components and make the size increase to the Device SDK smaller?"
A: No.
Q: "My App is already 50, 100, 150 (or more!) megabytes, and my users will think our App is huge if we add 3.9 more megabytes."
A: Your App is already huge, and probably needs to be optimized. We are experts in App thinning and have helped many customers with their Apps that are improperly thinned. Oftentimes, we have found that FaceTec adds less space to a customer’s App than a handful of already-existing, improperly thinned, and poorly optimized image resources in the customer App payload. Your App may also contain Swift. If you are using Swift, you have already made a conscious choice to make large sacrifices in the size of your Application.
Q: I think 3.9 megabytes (mobile) or 3.5 megabytes (Browser) is still too much. What else can you do?
A: If you desire Certified 3D Liveness Detection and Industry Leading 3D Matching performance, Camera Feed Encryption, and a great UX, you're going to need to have a Device SDK to manage the UI and security. The truth is, this is an extremely small add to your App for a huge benefit, and the concern over single-digit megabytes becomes less of a concern as each day passes because mobile devices offer more storage, cheaper data plans, and faster network technology.