Published by Niharika AroraDeveloper Relations Engineer
Construction for Android This includes paying particular attention to resource use and performance optimization.
Part 1 of this blog focuses on why developers should think about building. Android These tips will help you optimize your app memory. We also identified the most common approach for fixing performance issues. We will discuss other important aspects to consider when building apps. Android Go.
App optimization Android Go
Reduce startup latency
It is essential to have a good understanding of the factors that influence app startup times in order to improve it.
You can move tasks that are slowing down the main thread to another thread. Or, you could use WorkManager.
- Verify third-party library initialization
Third-party libraries that lazy load. Libraries often offer disabling or on-demand auto init options.
- You can check the rendering time for webp/png images
- Choose webp images instead of jpg/png
- For small icons, prefer svg
- Make sure to check for layouts that aren’t visible, and still allow time for images to be loaded.
- You can experiment with low resolution images by using the available memory on your device.
- Removing unnecessary background/alpha should be done.
- Use synchronous IPCs in UI threads. You should check for binder transactions that keep the main thread busy. Often, there is multiple Inter-process communication occurring within the app. These could be anything like image / asset loading, third party libs loading, heavy work on application’s main thread like disk or network access etc. StrictMode can be used by developers to identify such accidents.
To understand these transactions, identify and measure them.
- How much time does this take and if it is expected & necessary ?
- Are you noticing that the main thread is not working or idle? This could indicate a performance bottleneck.
- This can be postponed.
- Use Json and XML parsing sparingly Gboard used Java code to optimize file list parsing. This was because they were storing them in memory as Java objects during runtime. GBoard worked to convert all of the XML into Javacode at compile time. The latency is now time for class loading which is almost as fast, nearly. ⅕ Previous. You can benchmark both XML & Json parsing to determine which library is best for you app.
- Diagnose and correct severe disc read contention This can be captured by using StrictMode within your development environment.
- Detects network or accidental disk access to the main thread of the application, which is where UI operations and animations are performed.
- You can automatically close the app or log it to logcat if you have violated any terms.
Optimize app size
In emerging markets, where users are connected to poor 2G/3G networks at low speed and on pay-by the-byte plans, they often steer clear of downloading large apps.
- Eliminate any unnecessary layouts Gboard and Camera teams from Google validated layouts that were not used or can be merged with minor UI changes. They also removed unnecessary layouts, reducing the overall code size.
- When appropriate, migrate to dynamic layouts/views These apps do a deep dive to find layouts that can dynamically render. To further optimize views and layouts, they used viewstub and merge.
- Reevaluate any features that have low DAU. Disable features that use more memory, and reduce the app’s performance. Additionally, the team analyzed each app to determine which optimizations were needed. Android The Go team disabled certain features from go devices that weren’t used frequently but were taking up a lot of memory. The team removed large GIFs and complex animations. To make room for certain parts of the application.
- Combine native binaries and common dependencies to create one. The app may have multiple JNI implementations, with many common dependencies. All the binaries will add to the total apk file size. The Camera app from Google has combined several JNI binaries to create a single JNI binary, while still keeping Java and JNI separate. It helped reduce the size of the apk. Several Mbs.
- Reduce the size of your dalvik codes Look out for unneeded code at runtime.
- Code optimizers like ProGuard () While they could optimize code and reduce its size, they cannot deal with the underlying issues. codes Runtime-constants protect this information. Replace check/flags using compile time constants in order to maximize the use of the optimization tools.
- Translatable strings should be reduced in size
a. Don’t translate internal-only UI strings. Mark them as translatable = “false”.
b. Reduce unused alternativesUse the Android Use the Gradle plugin’s ResConfigs property for removing other resources files that your application does not require. Your app can use language resources such as AppCompat, Google Play Services or Google Play Services if it contains translated strings. You can use the resConfig property to specify only those languages you want your app to support. Resources for other languages are deleted.
Here’s a snippet: how to Limit your French and English language skills to English.
c. Don’t translate what doesn’t need translation: The string should not have a UI if it is not part of the UI. Strings used for debugging, exception messaging, URLs, and other purposes should not be translated.
i. Don’t translate what’s not shown to the user anyway
It’s possible to have a String resource that’s practically never shown to the user, but is still strongly referenced. One example is in your <activity>, if you have an Android:label set and referencing a String resource but the Activity’s label is never actually shown (e.g. it’s not a launcher Activity and it doesn’t have an app bar that shows its own label).
d. Don’t translate URLs: Take this as an example.
You may recognize < and > – these are escape characters for “<” and “>”. They’re needed here because if you were to put an <a> tag inside a <string> tag, then the Android resource compiler would just drop them (as it does with all tags it doesn’t recognize).
However, this means that you’re Translate the HTML tags into 78 languages. It is completely unnecessary.
Replace it with HTML
Note we don’t define a separate string for “Learn more”, because it’s a common string. We define the HTML code for the link in order to produce it.<a href=”https://support.google.com/androidauto/answer/6395843>%s</a>” as a string literals in code, and then drop the value of “Learn more” from resources into the format specifier.
e. Inline untranslated Strings: By specifying strings in strings.xml you can leverage the Android Framework that automatically changes the value at runtime according to the current configuration. Based on current location, display a localized version of the String).
f. Remove duplicate Strings: If you have the same string multiple times as a literal in code (“Hello World”), it will be shared across all instances. But resources don’t work this way – if you have an identical string under a different name then unless both are translated identically across 78 languages (unlikely) you’ll end up with duplicates.
Don’t have duplicate Strings!
g. Don’t have separate strings All CAPS Cases or Title Cases: Android Supports case mutations.
Use AndroidAPI Level 1: :capitalize This option specifies whether this TextView supports textual input methods and will capitalize the contents of what is entered. The default setting is “none”.
- Redefinition of asset size Make sure to consider the different device types your app can support and adapt your assets accordingly.
- Upload your app Android app bundles: Uploading your app as an Anonymous App to Google Play allows you to immediately save on app size when publishing it to Google Play. Android App Bundle, which is a new upload format that includes all your app’s compiled code and resources, but defers APK generation and signing to Google Play. Learn more.
- Use dynamic delivery features if you have them Play Feature delivery uses the advanced features of app bundles to allow certain features of your apps to be downloaded or delivered conditionally. You have the option to use feature modules for customized delivery. Using feature modules allows you to control how different features are downloaded on devices. Android 5.0 or greater (API level 21). You can find out more information here.
This blog shares best practices and recommendations from Google Apps to maximize your app’s size and startup latency, and enhance your user experience. It helps you drive adoption and user engagement for your app. Android app. You will learn the tools Google used to fix performance problems within their apps in part 3!