<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oleg  Beloy on Medium]]></title>
        <description><![CDATA[Stories by Oleg  Beloy on Medium]]></description>
        <link>https://medium.com/@olegbeloy?source=rss-cc14016796a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3hJNozFw4qVX4qqDZcIzTw.jpeg</url>
            <title>Stories by Oleg  Beloy on Medium</title>
            <link>https://medium.com/@olegbeloy?source=rss-cc14016796a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 11:22:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olegbeloy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Android CI: reveal manifest changes in a pull request]]></title>
            <link>https://proandroiddev.com/android-ci-reveal-manifest-changes-in-a-pull-request-a5cdd0600afa?source=rss-cc14016796a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5cdd0600afa</guid>
            <category><![CDATA[continious-integration]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[androidmanifest]]></category>
            <dc:creator><![CDATA[Oleg  Beloy]]></dc:creator>
            <pubDate>Sat, 15 Oct 2022 20:28:43 GMT</pubDate>
            <atom:updated>2023-01-03T15:29:46.102Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>[Android CI] Reveal manifest changes in a pull request</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZTIBa3BkWSBvStjwQAUodw.png" /></figure><h3><strong>The problem</strong></h3><p>Each android application must have a bundled global manifest file. The manifest declares permissions used by the app, provides an information for android system, declares android components used in the app etc..</p><p>It contains sensitive information for us, such as unnecessary or <a href="https://source.android.com/docs/core/permissions/runtime_perms">dangerous permissions</a> which we want to avoid, credentials, which we must include or important app properties. It is beneficial to have a way to quickly analyse the changes to manifest and have more control over them.</p><p>A bundled manifest <a href="https://developer.android.com/studio/build/manage-manifests#merge-manifests">is merged</a> from the sources by gradle in the end of assemble task. Because of the nature of the sources we can not just check all git changes in every app and library manifest, because it could be affected by any of dependencies we have.</p><h3>Goals</h3><p>It would be much better if we can simply see and compare only the changes provided by the current feature pull request since the last approved build.</p><p>So, in simple words goals of this functionality are to:</p><ul><li>Show clean and simple way to check&amp;verify the app manifest changes</li><li>Show difference between current and the released app manifest</li><li>Show difference between current and the main branch manifest</li><li>Easily check new or removed app permissions</li><li>Easily check attributes/credentials manifest changes</li><li>Show a way to verify manifest changes using a pull request mechanism</li><li>Support easy setup under any environment</li></ul><h3>Implementation</h3><p>Having all the mentioned dependencies and environment variables provided the scripts below could be launched in any CI environment, such as circleCi, github actions, jenkins etc. Check the last paragraph for details.</p><h4>Preconditions</h4><ul><li>dependencies are available/installed &amp; environment variables are set</li><li>assemble{build variant}gradle task has completed</li><li>deployment has completed before updating a baseline manifest for current release</li></ul><h4>High level steps</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aeR-miajCK3iXSqd0InCvw.png" /></figure><p>Let’s make our hands dirty. To implement those on a high level we should have the abilities:</p><ul><li>find merged manifest</li><li>sort merged manifest. <em>Gradle</em> could merge manifest i<a href="https://developer.android.com/studio/build/manage-manifests#merge_priorities">n any order for those with same priority</a>. This step is required to reduce false attraction.</li><li>store merged manifest as baseline</li><li>input manifest must remain untouched</li><li>update &amp; store baseline manifest after release</li><li>update &amp; store baseline manifest for development branch</li><li>find diff between baseline and the current manifest</li><li>upload and display manifest changes in a corresponding pull request</li></ul><h4>Find merged manifest</h4><p>To display manifest changes firstly we need a current comparable manifest.</p><blockquote>When building your app, the Gradle build merges all manifest files into a single manifest file that’s packaged into your app.</blockquote><p>It is what we need and it is going to be used in a diff task.</p><p>Let’s extract, sort and store the manifest here in some buffer directory to simplify an access to it further in the workflow. We may persist &amp; publish the manifest merger log as well for debug purposes to be able to debug and understand the source of any manifest line in case some unexpected change has happened</p><blockquote>Let’s extract, sort and store the manifest</blockquote><p>Launch the script in a separated step after completion of assemble task.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35a188e9b0fa574b6daeb38a6aa94117/href">https://medium.com/media/35a188e9b0fa574b6daeb38a6aa94117/href</a></iframe><p>Note that in special cases there might be more than 1 app per project and several build configurations. That’s why we pass name and configurations like debug , release , qa as a parameters to the script</p><p>/intermediates/merged_manifest/$BUILD_TYPE/ and /outputs/logs/manifest-merger-$BUILD_TYPE-report.txt are paths in a build folder declared by gradle. These paths may change with gradle version change. The article is written for AGP 7.2.1</p><h4>Prepare to compare: sort merged manifest</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ozanmw5GbvVLPQhmUHQ5BQ.png" /></figure><p>Assuming gradle could merge the manifest in a shuffled order to collect stable results we need to sort the resulting manifest using our custom algorithm.</p><p>We are interested only in changes and won’t modify initial manifest, so we are absolutely safe to do that. But better to keep usual order of the manifest tags for readability</p><p>So we our algorithm should sort the tags by:</p><ul><li>prioritising special top tags: uses-sdk , uses-feature , uses-permission , permission</li><li>tag, as default ordering key</li><li>android:name attribute to order same tags, &lt;uses-permission&gt;or &lt;activity&gt; for example</li></ul><p>It would be hard to do the job with bash. That’s why we are going to attach python3 and tidy dependencies here. Python is needed for its powerful ElementTree and sorting mechanism, and tidy is used to prettify the results for better readability. You can take <a href="https://github.com/BelooS/android-ci-scripts/blob/main/manifest/tidy.ini">tidy config here</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3333b2cca8fa6f78b35e13c73b03167/href">https://medium.com/media/c3333b2cca8fa6f78b35e13c73b03167/href</a></iframe><p>After the script completion we received a sorted clone of the merged manifest</p><h4>Where to save a baseline?</h4><p>We need to store latest release &amp; stable development manifests somewhere, better not in the main project directory to not pollute main git tree with automatic commits. We are going to use <strong>sorted</strong> manifest from the previous step</p><p>Our decision was to store it in the special folder of github wiki. For sure, that’s not really how it is supposed to be used, but that fit our needs perfectly.</p><p>Firstly the manifest could be easily stored there by using standard git commands and then obtained the same way by request. Secondly, only md files are displayed in github ui, but any file could be stored. Thirdly, it hadn’t been used in our project anyway :)</p><p>Github wiki is a special git repository, so we should git clone it, move manifest from workspace dir to wiki dir, commit our changes (which would be particularly a baseline manifest update) and push back</p><p><strong>Alternatively</strong> you could use an additional repository just for the purpose of persisting the data to not the main repository.</p><blockquote>Github wiki is a special git repository, so we should clone it</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e0f77875c4e9ec305cfcf64d784714b/href">https://medium.com/media/8e0f77875c4e9ec305cfcf64d784714b/href</a></iframe><blockquote>move manifest from workspace dir to wiki dir</blockquote><p>By using the provided BUILD_TYPE we may find and copy sorted manifest to wiki dir. There are might be several of them for multi-app project like mine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27579d2914cf4711ff928fc9be2a8334/href">https://medium.com/media/27579d2914cf4711ff928fc9be2a8334/href</a></iframe><blockquote>commit our changes and push back.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a25deae34fcbedc6e2280e703ac4a827/href">https://medium.com/media/a25deae34fcbedc6e2280e703ac4a827/href</a></iframe><p>Universal script push_changes_from_directory.sh is used to push the changes. It would be too verbose to post it here, <a href="https://gist.github.com/BelooS/c099251a8f7e78c0d5839fa2d5989f47">check the reference</a> though.</p><p>Execute this step after assembleDebug gradle task in a main development branch, where all pull requests are merged to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2W1-BE-z8gKmK9tZJ2eWFw.png" /><figcaption>update main manifest baseline after `build debug` in a development branch</figcaption></figure><p>Or <strong>after deployment </strong>of a release by continuous delivery pipeline. Should be skipped for an ordinary pull request and be in a separated job because of that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*adz89JNEQW-ROKWOi_Kkvw.png" /><figcaption>update release manifest baseline after deployment in a release branch</figcaption></figure><h4>Finally! Find and post a difference to pull request</h4><p>In the final step we are going to take sorted manifest which we generated previously, find a difference between baseline manifest and the one and post the result to github.</p><p>A we discussed previously there might be not only one application/library of what we want to track a manifest. Script just relies on the file structure which has been created before.</p><p>Linuxdiff util is used to collect those differences and store them to a file. I suppose that git diff command uses this util under hood as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cae5e0f87616a66a71f9ef1ccc7ad84b/href">https://medium.com/media/cae5e0f87616a66a71f9ef1ccc7ad84b/href</a></iframe><p>In a real world we may restart a build several times and don’t want to spam a lot in pr comments. So we use <a href="https://github.com/BelooS/android-ci-scripts/blob/main/github/remove_github_comment.sh">remove_github_comment.sh</a> script for cleanup. The message tag should be passed to it.</p><h4>Dependencies</h4><ul><li><strong>bash</strong></li><li><strong>python3.9</strong></li><li><a href="https://github.com/htacg/tidy-html5"><strong>html-tidy library</strong></a><strong> 5.9.14</strong></li><li><a href="https://www.geeksforgeeks.org/diff-command-linux-examples/"><strong>diff tool</strong></a></li><li><a href="https://cli.github.com/">github cli</a></li></ul><p>The last one is not really necessary, it is only an api of pull request management system to post the result. If you use bitbucket, for example, you should use its api for that.</p><h4>Environmental variables</h4><p>I have used several environmental variables for the scripts. There are most of them:</p><p><strong>WORKSPACE</strong>: workspace path, typically root directory of the project for CI build<br><strong>MANIFESTS_WORKSPACE_DIR</strong>: directory in the workspace where we keep sorted manifest between CI jobs<br><strong>WIKI_DIR</strong>: directory in github wiki where we store baseline manifests<br><strong>PULL_REQUEST_URL</strong>: browser url of a pull request<br><strong>PULL_REQUEST_ID</strong>: id of the current pull request, last path segment of <em>PULL_REQUEST_ID</em><br><strong>GITHUB_TOKEN</strong>: personal user’s github token which must be provided to operate with github api directly. You should have a service account, which is going to post the comments in a pull request<br><strong>GITHUB_PROJECT_USERNAME</strong>: name of a user or an organisation where the project is located<br><strong>GITHUB_PROJECT_NAME</strong>: name of a repository where the project is hosted</p><p><em>That’s it!</em></p><p><em>Thank you for reading and have fun while integrating! Any comments are welcome</em></p><p><em>If you found this post to be useful and interesting, you may give </em><strong><em>up to 50</em></strong><em> claps and recommend it :)</em></p><p>&gt; 250 claps and i’ll build a corresponding <a href="https://circleci.com/developer/orbs">circleCi orb</a> and <a href="https://github.com/marketplace?type=actions">github action</a> 🔥</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5cdd0600afa" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/android-ci-reveal-manifest-changes-in-a-pull-request-a5cdd0600afa">Android CI: reveal manifest changes in a pull request</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>