
Lin Wang | Android Efficiency Engineer
It’s a widely known reality for Android builders that an app’s manifest (AndroidManifest.xml) holds essential utility declarations. It’s hardly ever monitored after being arrange as a result of we assume it infrequently modifications. At Pinterest, nonetheless, we’ve been actively monitoring the manifest after realizing it does change sometimes.
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. Through the construct course of, Android Gradle Plugin (AGP) merges them with the app’s important manifest to type the ultimate manifest. Due to this merging course of, the ultimate manifest usually seems to be fairly totally different from the unique one and incorporates extra declarations. Typically, these additional declarations are essential for dependent libraries to operate. Nonetheless, typically they’ll have unintended behaviors.
It first caught our consideration throughout a chilly begin regression investigation. We discovered a third get together Software program Growth Package (SDK) declaring a particular ContentProvider in its manifest to heat up itself as early as attainable. It’s because content material suppliers get initialized very early throughout the utility startup, even earlier than the Utility’s onCreate() technique is invoked. Nonetheless, we need to management each third get together libraries’ initialization and solely initialize them when it’s essential. Due to this fact, we added the next declaration:
Including this declaration to the manifest will trigger the SdkEarlyInitializer to be faraway from the ultimate merged manifest. This modification resulted in a chilly begin enchancment of 130ms.
From then on, we created the next course of to recurrently monitor the merged manifest modifications earlier than touchdown a commit, beginning with taking a snapshot of the present merged manifest and protecting it within the codebase:
- As a part of the PR construct, we evaluate the merged manifest towards the snapshot.
- If a distinction is detected, we fail the construct.
- The PR developer should then alter the snapshot manifest if the modifications are essential, or add the correct “take away” tags to maintain the brand new elements out of the ultimate manifest.
A small group of blocking reviewers will evaluation 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 continued 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 adequate to check manifests
- AGP does typically reorder the objects in manifest with out altering the content material, through which case the snapshot must be adjusted
- Ignoring white areas and newlines is important
- Often modified objects within the manifest have to be explicitly ignored (e.g. UUIDs, model codes)
With this method, we will likely be alerted when any new element will get added to our app and really feel extra assured at any time when we add new dependencies.
Android Efficiency Crew: Arun Okay, Ernesto Duhart, Lin Wang, Sheng Liu, Tom Harman
Particular Thanks: Sha Sha Chu (She Her)
To study extra about engineering at Pinterest, try the remainder of our Engineering Weblog and go to our Pinterest Labs website. To discover life at Pinterest, go to our Careers web page.