Xcode 11 is a fundamental developing tool that includes everything needed to create amazing apps for all Apple platforms. It consists of the latest SDKs for macOS 10.15, iOS 13, iPadOS 13, watchOS 6, and tvOS 13. Xcode 11 includes SwiftUI, a framework that provides views, controls, and layout structures for declaring an app’s UI.
SwiftUI is the latest way to declare user interfaces for an iOS platform and create amazing and dynamic apps faster than ever before. Swift eliminates common programming errors by adopting modern programming patterns. SwiftUI eliminates entire classes of unsafe code and adds great new features to make sharing code across Apple’s platforms even easier.
Variables are always initialized before use.
Arrays and integers are checked for overflow
Memory is automatically managed.
Ability to exclusively access memory guards against many programming mistakes.
“Swift has been years in the making, and it continues to evolve with new features and capabilities”. At Apple WWDC20 it was mentioned that their goals for Swift are ambitious and that they are eager to see what developers create with it.
SwiftUI introduced developers to a modern UI framework that can help build sophisticated and agile app UIs. Bringing together the global Apple developer community of more than 23 million in a phenomenal and virtual way, Apple announced a plethora of latest enhancements in the swift programming language.
Latest Enhancements in SwiftUI
1. Redesigned widgets
With redesigned widgets on the Home Screen pages, users can experience the developer’s widget every time they look at their device. With new extensions to the SwiftUI API, developers can use the same code to build a widget for iOS, iPadOS, and macOS simultaneously. SwiftUI can be used to create custom complications for WatchOS.
2. Easy Sharing
Swift Package Manager enables easy sharing of Asset Catalog bundles and localizations. .matchedGeometryEffect to provide fluid animations inside of a grid of UI elements. Custom fonts shall automatically scale with dynamic type changes.
3. Extended Use Cases
New open-source packages have been introduced for Numerics, ArgumentParser, and System making Swift a great language for more use cases. It will be able to support basic math functions as well as complex numbers.
4. App-structure APIs
SwiftUI now contains app-structure APIs for all Apple platforms, e.g. @main, @SceneBuilder, Settings etc and WindowGroup to manage windows platform independently.
5. Extended SwiftUI Capabilities
Now developers can write an entire app in SwiftUI using the life cycle API and share it across all Apple platforms. struct BookClubApp: App
6. Simplified App Upgrade
Developers already working with swift can now easily add features to their existing code. Lazy API (Lazy[V|H]Stack) can be used to reduce memory footprint and offer smooth navigation for enormous amounts of data.
With the increase in mobile storage spaces that have gone up to 256 GB, app size is also growing. App size is sure to grow as developers are adding new features, trying to meet customer needs, and also trying to support their apps on various screen sizes. Around 74% of the world uses Android, and 70% of users consider app size before installing them. Moreover, as humans are getting accustomed to instant gratification, they ponder on ways to download apps as they take up storage spaces. Despite the cloud support for photos, videos, and files, android users face issues, such as mobile hanging due to app size. As customer expectations are increasing, android app developers are considering other ways to reduce app size while still incorporating significant additional features and keeping in mind the customer experience.
Below are the 8 best ways to reduce android app size:
1. Use Android App Bundleto Reduce App Size
When generating the release version of your app, you can choose between APK and Android App Bundle. The second option will make Google play to generate the APK with only those features a specific user need.
App Bundle Vs APK
Android App Bundle
It is a publishing format that includes compiled code and resources of your app, and delays APK generation and signing to Google Play.
Download Android Studio 3.2 or higher—it’s the easiest way to add feature modules and build app bundles.
Add support for Play Feature Delivery by including a base module, organizing code and resources for configuration APKs, and, optionally, adding feature modules.
Build an Android App Bundle using Android Studio. You can also deploy your app to a connected device from an app bundle by modifying your run/debug configuration and selecting the option to deploy APK from app bundle. Keep in mind, using this option results in longer build times when compared to building and deploying only an APK.
If you’re not using the IDE, you can instead build an app bundle from the command line.
Test your Android App Bundle by using it to generate APKs that you deploy to a device.
Enroll into app Play App Signing. Otherwise, you can’t upload your app bundle to the Play Console.
Publish your app bundle to Google Play.
Please note: Android Package Kit – As per developer console, by the mid of 2021, developers won’t be able to upload apk on play store)
Android operating system uses APK which is the package file format for distribution and installation of mobile apps, games and middleware. APK is similar to other software packages such as APPX in Microsoft Windows or a Debian package in Debian -based operating systems.
Google Play requires that the compressed APK downloaded by the users should not exceed 100 MB.
The expansion files for your app are hosted by Google Play which serves them to the device at no cost to you. The expansion files are saved to the device’s shared storage location (the SD card or USB-mountable partition).
2. Use Proguard
Proguard is probably one of the most useful tools to reduce your APK size. It reduces the source code files to a minimum and can reduce the APK file size upto 90%.
Use it in all variants whenever using “Proguard”
Helps to avoid conflict at the of generate apk or bundle if will use in all the variants.
We cannot let ProGuard rename or remove any fields on these data classes, as they have to match the serialized format. It’s a safe bet to add a @Keep annotation on the whole class or a wildcard rule on all your models.
3. Use Android Size Analyzer Plugin
This Android Studio plugin will provide you recommendations to reduce the size of your application.
With the APK Analyzer, you can accomplish the following:
View the absolute and relative size of files in the APK, such as the DEX and Android resource files.
Understand the composition of DEX files.
Quickly view the final versions of files in the APK, such as the AndroidManifest.xml file.
Perform a side-by-side comparison of two APKs.
There are three ways to access the APK Analyzer when a project is open:
Drag an APK into the Editor window of Android Studio.
Switch to the Project perspective in the Project window and then double-click the APK in the default build/output/apks/ directory.
Select Build > Analyze APK in the menu bar and then select your APK.
Whether used or not, every resource takes up memory. It is therefore necessary to have only those resources that you need, and to use those in a memory efficient way. In other words, you should consider the resolution of the image before finalizing on it.
5. Optimize Libraries
As large libraries consume huge amounts of space, it is advisable to remove parts of it in case you do not need them and if it is permitted by the license of the library. Proguard can aid you in this process but it is not always able to remove large internal dependencies.
6. Use Vector Graphics Wherever Possible
They are sharp and do not consume much space as they rely on mathematical calculations and not on pixels that need to be saved. However, they cannot be used for photography.
7. Compress Your Images
By using tools such as pngcrush, you can reduce the file size of PNG images. It is advisable to do this images as they still look the same.
8. Only Support Specific Densities
If only a small portion of users use a specific density, it might be better to let Android scale your other densities for them as it would reduce your APK size.
As mobile storage space is growing, people are installing a large number of apps to meet a wide range of needs. But as app size is increasing, people are continuing to struggle with storage issues. With provisions such as Proguard, one can compress the APK file size and optimize libraries easily. Compressing images and using vector graphs are also useful in reducing app size.
About the author: Anand Singh is Tech Lead at Mantra Labs. He is integral to the company’s Android-based projects and enterprise application development.