Watch your Manifest. Lin Wang | Android Efficiency Engineer | by Pinterest Engineering | Pinterest Engineering Weblog | Oct, 2022

Lin Wang | Android Efficiency Engineer

Black magnifying glass with “</” inside of the glass portion and “manifest >” to the right of the magnifying glass
Designed by AJ Oxendine | Software program Engineer

It’s a well known reality for Android builders that an app’s manifest (AndroidManifest.xml) holds essential utility declarations. It’s not often monitored after being arrange as a result of we assume it rarely modifications. At Pinterest, nevertheless, now we have been actively monitoring the manifest after realizing it does change from time to time.

Whereas constructing an app, Gradle downloads all of the dependent libraries to compile and hyperlink them with the app. These dependent libraries every have their very own mini manifest. Throughout the construct course of, Android Gradle Plugin (AGP) merges them with the app’s principal manifest to kind the ultimate manifest. Due to this merging course of, the ultimate manifest usually appears to be like fairly totally different from the unique one and accommodates extra declarations. Typically, these additional declarations are crucial for dependent libraries to perform. Nevertheless, typically they will have unintended behaviors.

It first caught our consideration throughout a chilly begin regression investigation. We discovered a third social gathering Software program Growth Equipment (SDK) declaring a particular ContentProvider in its manifest to heat up itself as early as doable. It is because content material suppliers get initialized very early throughout the utility startup, even earlier than the Software’s onCreate() technique is invoked. Nevertheless, we wish to management each third social gathering libraries’ initialization and solely initialize them when it’s crucial. Due to this fact, we added the next declaration:

<provider android:name=”” … other android properties … tools:node=”remove”/>

Including this declaration to the manifest will trigger the SdkEarlyInitializer to be faraway from the ultimate merged manifest. This variation resulted in a chilly begin enchancment of 130ms.

From then on, we created the next course of to usually monitor the merged manifest modifications earlier than touchdown a commit, beginning with taking a snapshot of the present merged manifest and maintaining it within the codebase:

  1. As a part of the PR construct, we examine the merged manifest towards the snapshot.
  2. If a distinction is detected, we fail the construct.
  3. The PR developer should then regulate the snapshot manifest if the modifications are crucial, or add the right “take away” tags to maintain the brand new parts out of the ultimate manifest.

A small group of blocking reviewers will overview each manifest change.

  • Found the WorkManagerInitializer (ContentProvider), which was added by the work supervisor library. We firstly eliminated it and notified Google, who ultimately added assist for initializing the work supervisor with a custom configuration.
  • Discovered a brand new intent was added by upgrading of the exoplayer library to 2.15.0. We then contributed to the continuing issue discussion with Google to lastly have this pointless intent eliminated.
  • Detected the AD_ID permission was added by a library.
  • The common cshell diff is ample to match manifests
  • AGP does typically reorder the gadgets in manifest with out altering the content material, wherein case the snapshot must be adjusted
  • Ignoring white areas and newlines is important
  • Ceaselessly modified gadgets within the manifest must be explicitly ignored (e.g. UUIDs, model codes)

With this method, we can be alerted when any new part will get added to our app and really feel extra assured each time we add new dependencies.

Android Efficiency Workforce: Arun Okay, Ernesto Duhart, Lin Wang, Sheng Liu, Tom Harman

Particular Thanks: Sha Sha Chu (She Her)

To be taught extra about engineering at Pinterest, take a look at the remainder of our Engineering Weblog and go to our Pinterest Labs website. To discover life at Pinterest, go to our Careers web page.