<?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 Prathap Kumar on Medium]]></title>
        <description><![CDATA[Stories by Prathap Kumar on Medium]]></description>
        <link>https://medium.com/@prathapkumar_l?source=rss-356343077a19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6gtB8ugS_Tw7g_2W6fY0Fw.jpeg</url>
            <title>Stories by Prathap Kumar on Medium</title>
            <link>https://medium.com/@prathapkumar_l?source=rss-356343077a19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:43:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prathapkumar_l/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[Understanding Dependency Configurations in Native Android (Gradle)]]></title>
            <link>https://medium.com/@prathapkumar_l/understanding-dependency-configurations-in-native-android-gradle-61d3122ea23a?source=rss-356343077a19------2</link>
            <guid isPermaLink="false">https://medium.com/p/61d3122ea23a</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[dependency-management]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Prathap Kumar]]></dc:creator>
            <pubDate>Sat, 31 Jan 2026 02:05:48 GMT</pubDate>
            <atom:updated>2026-01-31T02:05:48.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rc7i5viL5xJPA4CXucZr5g.png" /></figure><p>If you’ve worked on Android long enough, you’ve probably added dependencies like implementation, api, or testImplementation without fully questioning <em>why</em> one is preferred over another. It works — until it doesn’t.</p><p>In modern Android development, especially with <strong>multi-module architecture</strong>, choosing the right dependency configuration is critical for <strong>build performance</strong>, <strong>encapsulation</strong>, <strong>test isolation</strong>, and <strong>maintainability</strong>.</p><p>This article breaks down <strong>all major dependency configurations in native Android</strong>, explains <strong>what they do</strong>, <strong>when to use them</strong>, and <strong>common mistakes to avoid</strong>.</p><h3>Why Dependency Configurations Matter</h3><p>Gradle dependency configurations control:</p><ul><li>Who can see a dependency</li><li>When it’s available (build type / test / runtime)</li><li>How much it leaks into other modules</li><li>How fast your project builds</li></ul><p>Wrong choices lead to:</p><ul><li>Slower builds 🚫</li><li>Unintended dependency exposure 🔓</li><li>Hard-to-maintain module boundaries 😵‍💫</li></ul><p>Let’s fix that.</p><h3>1. implementation (The Default &amp; Recommended)</h3><p>When you write implementation inside dependencies block in gradle file, you’re telling Gradle <strong>“this dependency is needed only inside this module, not outside it.”</strong> This is the most commonly used and <strong>default-safe</strong> way to add dependencies in modern Android and Java projects. It is introduced to replace compile ( which is now deprecated) to improve <strong>incremental build performance</strong>.</p><pre>//Deprecated<br>compile(&quot;com.squareup.retrofit2:retrofit:2.11.0&quot;)<br><br>implementation(&quot;com.squareup.retrofit2:retrofit:2.11.0&quot;)</pre><p>Here, Retrofit is only used inside the module, so implementation is perfect.</p><h4>What it does</h4><ul><li>Adds the dependency <strong>only to the current module</strong></li><li><strong>Does NOT expose</strong> it to modules that depend on this module</li></ul><h3>When you should use implementation</h3><p>Use implementation in <strong>most cases</strong>. If you’re unsure, this is almost always the right choice.</p><ul><li><strong>Internal usage only</strong><br> When the dependency is used only inside the current module (activities, view models, repositories, helpers, etc.).</li><li><strong>App modules</strong><br> In app modules, nearly all dependencies should be implementation because no other module depends on your app.</li><li><strong>Library modules (internal details)</strong><br> If your library uses something internally (like Retrofit, Room, Gson) but <strong>does not expose those types in its public API</strong>, use implementation.</li><li><strong>Faster builds</strong><br> implementation reduces the dependency graph that Gradle exposes to other modules, which <strong>improves build times</strong> and incremental compilation.</li></ul><h3>When you should NOT use implementation</h3><p>You should <strong>not</strong> use implementation when the dependency is <strong>part of your module’s public API</strong>.</p><ul><li><strong>Library modules exposing types</strong><br> If your module returns or accepts classes from that dependency in public methods, interfaces, or models, implementation will break consumers.</li></ul><p>In the below example,</p><pre>// Public API of a library<br>fun createService(): Retrofit</pre><p>If Retrofit is added using implementation, another module calling this function <strong>will not see </strong><strong>Retrofit</strong>, causing compile errors. In this case, you must use api instead.</p><h3>2. api (Be Careful With This One)</h3><p>Use <strong>api</strong> only when a dependency is part of your module’s <strong>public contract</strong>. This means other modules that depend on your module must be able to see and use that dependency’s classes. For example, if your library exposes a third-party type in a public method, return value, parameter, or interface, then you must use api.</p><h4>What it does</h4><ul><li>Adds the dependency to the module</li><li><strong>Exposes it transitively</strong> to dependent modules</li></ul><p>Misusing <strong>api</strong> can be dangerous because it exposes too much to other modules. It increases build times by forcing Gradle to recompile more code, breaks encapsulation by leaking internal implementation details, and can cause dependency conflicts in modules that depend on yours.</p><blockquote>The golden rule is simple: <strong>if other modules don’t need to use that dependency directly, do not use </strong><strong>api</strong>.</blockquote><h3>3. compileOnly (Provided at Compile Time Only)</h3><p>Use <strong>compileOnly</strong> when a dependency is needed <strong>only at compile time</strong>, but should <strong>not be included in the final APK or AAR</strong>.</p><p>Common examples include Android annotations, lint APIs, or optional plugin-style integrations. In short, choose <strong>compileOnly</strong> when you need the classes to compile your code, but you do not want Gradle to package them or force them onto consumers.</p><h4><strong>What it does</strong></h4><ul><li>Available <strong>only during compilation</strong></li><li><strong>Not included</strong> in APK/AAB</li></ul><h4>Example usage:</h4><pre>// Example<br>dependencies {<br>  compileOnly(&quot;com.android.tools.lint:lint-api:31.2.0&quot;)<br>  compileOnly(&quot;com.android.tools.lint:lint-checks:31.2.0&quot;)<br>}</pre><h3>4. runtimeOnly (Runtime but Not Compile Time)</h3><p>runtimeOnly is the exact opposite of compileOnly, Use runtimeOnly when a dependency is <strong>not needed to compile your code</strong>, but <strong>is required when the app is running</strong>. This usually happens when your code depends on an interface or abstraction at compile time, and the actual implementation is loaded only at runtime.</p><h4>What it does</h4><ul><li>Included <strong>only at runtime</strong></li><li>Not available during compilation</li></ul><h4>When to use</h4><p>Rare in Android, but useful when:</p><ul><li>Using reflection</li><li>Plugin-based architectures</li><li>Database drivers</li></ul><p>In simple terms, choose runtimeOnly when the dependency is invisible to your code during compilation but essential for the app to work at runtime.</p><h3>5. kapt / ksp (Annotation Processing)</h3><p><strong>kapt and </strong><strong>ksp</strong> are used when you work with <strong>annotation processing</strong>, which means generating code during build time instead of writing everything manually.</p><pre>kapt(&quot;com.google.dagger:hilt-compiler:2.51&quot;)</pre><p>Use <strong>kapt</strong> when a library still relies on Java’s annotation processing system (APT). Many older or Java-based libraries use this. For example, Room, Dagger, or Hilt (internally) generate code using annotations, and kapt runs those processors during compilation.</p><pre>ksp(&quot;com.google.devtools.ksp:symbol-processing-api&quot;)</pre><p>Use <strong>ksp</strong> when the library supports <strong>Kotlin Symbol Processing</strong>, which is a newer and faster approach designed specifically for Kotlin. ksp is more efficient than kapt because it understands Kotlin directly and avoids Java stubs, resulting in faster builds and better performance.</p><blockquote>Prefer <strong>KSP over KAPT</strong> whenever supported — it’s faster and incremental.</blockquote><h3>6. testImplementation</h3><p>testImplementation is used for dependencies that are needed <strong>only for unit testing</strong> and not for the main app code. These dependencies are available only in the test source set, which runs on the local JVM.</p><p>Common examples include testing frameworks like JUnit, Mockito, or Truth. Using testImplementation keeps your production code clean, reduces APK size, and ensures test libraries are not included in release builds.</p><pre>// Example<br>dependencies {<br>  testImplementation(libs.junit)<br>}</pre><h4>What it does</h4><ul><li>Available <strong>only to unit tests</strong></li><li>Not packaged into production APK</li></ul><p>In simple terms, use testImplementation for anything that helps you write or run unit tests, but is not required by the app at runtime.</p><h3>7. androidTestImplementation</h3><p>androidTestImplementation is used for dependencies that are needed <strong>only</strong> <strong>for instrumented tests</strong>, which run on a real device or emulator. These tests live in the androidTest source set and are used for UI testing and integration testing.</p><p>Common examples include Espresso, UI Automator, and AndroidX test libraries. Using androidTestImplementation ensures these testing tools are not included in your main app code or unit tests.</p><pre>// Example<br>dependencies {<br>  androidTestImplementation(&quot;androidx.espresso:espresso-core:3.5.1&quot;)<br>}</pre><h4>What it does</h4><ul><li>Available <strong>only to instrumented tests</strong></li><li>Runs on emulator or real device</li></ul><h3>8. debugImplementation</h3><p>debugImplementation is used for dependencies that should be included <strong>only in debug builds</strong> and not in release builds. This is helpful for tools used during development, such as debugging, logging, inspection, or UI testing utilities.</p><p>A common example is LeakCanary, which helps detect memory leaks but should never be shipped to production. Using debugImplementation keeps your release APK smaller, safer, and free from development-only tools.</p><pre>// Example<br>dependencies {<br>  debugImplementation(&quot;com.squareup.leakcanary:leakcanary-android:2.14&quot;)<br>}</pre><h4><strong>What it does</strong></h4><ul><li>Included <strong>only in debug builds</strong></li><li>Excluded from release builds</li></ul><p>In simple terms, use debugImplementation for dependencies meant only for development and debugging.</p><h3>9. releaseImplementation</h3><p>releaseImplementation is used for dependencies that should be included <strong>only in release builds</strong> and not in debug builds. This is useful when you want different behavior in production, such as using a no-op or lightweight version of a library instead of a debug one.</p><p>A common case is logging, where debug builds use detailed logs, but release builds use a minimal or empty implementation for performance and security.</p><pre>// Example<br>dependencies {<br>  releaseImplementation(&quot;com.example:analytics-prod&quot;)<br>}</pre><h4><strong>When to use</strong></h4><ul><li>Different implementations per build type</li><li>Debug vs production analytics</li><li>Mock vs real services</li></ul><p>In simple terms, use releaseImplementation when a dependency is needed only for the final, production version of your app.</p><h3>Final Thoughts</h3><blockquote>Dependency configurations are not just Gradle syntax, they’re architecture decisions.</blockquote><p>Using these configurations correctly improves build speed, keeps module boundaries clean, prevents dependency conflicts, and helps make your project simpler, more maintainable, and scalable as it grows.</p><p>If you’re building multi-module Android apps, mastering these configurations is non-negotiable.</p><p>If you’re building <strong>multi-module Android apps</strong>, mastering these configurations is non-negotiable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61d3122ea23a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering BundleTool: Convert AABs into APKs Like a Pro]]></title>
            <link>https://medium.com/@prathapkumar_l/mastering-bundletool-convert-aabs-into-apks-like-a-pro-861dc382391f?source=rss-356343077a19------2</link>
            <guid isPermaLink="false">https://medium.com/p/861dc382391f</guid>
            <category><![CDATA[android-development-tools]]></category>
            <category><![CDATA[android-app-distribution]]></category>
            <category><![CDATA[android-app-bundle]]></category>
            <category><![CDATA[bundletool-guide]]></category>
            <category><![CDATA[apk-generation]]></category>
            <dc:creator><![CDATA[Prathap Kumar]]></dc:creator>
            <pubDate>Sun, 28 Sep 2025 12:52:46 GMT</pubDate>
            <atom:updated>2025-09-28T12:52:46.777Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*Q7DgvfHMBaKB6mhXkRk8Aw.jpeg" /></figure><p>Google Play has shifted away from <strong>APK uploads</strong> and requires developers to publish apps using <strong>Android App Bundles (AABs) </strong>from a long time. This change unlocks several advantages for users and developers alike:</p><ul><li>Smaller downloads through optimized APKs</li><li>Dynamic delivery of features and languages</li><li>Better device targeting</li></ul><p>But with this new format comes a new workflow. What if you need to <strong>test your app locally</strong>, <strong>share an installable APK with QA teams</strong>, or <strong>sideload the app without playstore</strong>?</p><p>You cannot install an .aab file directly to your android device. That’s where <strong>BundleTool</strong> comes in. BundleTool is the <strong>official command-line tool from Google</strong> that converts .aab files into .apk files, mimicking how playstore generates and delivers APKs to devices.</p><p>In this guide, I’ll walk you through everything you need to know to:</p><ul><li>Generate APKs from an AAB</li><li>Extract and install them on real devices</li><li>Avoid common errors developers run into</li><li>Automate the process for CI/CD pipelines</li></ul><p>👉 Official Docs: <a href="https://developer.android.com/tools/bundletool">BundleTool on developer.android.com</a></p><h3>Know about BundleTool</h3><blockquote>bundletool is the underlying tool that Android Studio, the Android Gradle plugin, and Google Play use to build an Android App Bundle. bundletool can convert an app bundle into the various APKs that are deployed to devices.</blockquote><ul><li>It builds APKs from .aab files.</li><li>It installs those APKs on a connected device.</li><li>It lets you test split APKs exactly as Google Play would deliver them.</li></ul><p>In short, BundleTool is the bridge between your <strong>App Bundle (AAB)</strong> and the <strong>installable APKs</strong>.</p><h4>💡 When BundleTool Comes in Handy</h4><p>BundleTool isn’t just a publishing tool — it’s also a lifesaver in everyday development scenarios. Imagine you’ve just finished a release build and want to share an installable APK with your QA team, but the Play Store upload/review cycle would take too long. Or maybe you’re testing device-specific behavior on different screen densities and languages without uploading multiple times. In these cases, generating APKs directly from your AAB with BundleTool lets you <strong>bypass delays, quickly sideload on devices, and replicate Play Store’s app delivery process locally</strong>.</p><p>👉 Remember:</p><ul><li>.aab → Upload to Play Store.</li><li>.apk → Install on devices.</li><li><strong>BundleTool</strong> bridges the gap.</li></ul><h3>Step by step guide to how to use BundleTool</h3><h4>🔹 Step 1: Download BundleTool</h4><ol><li>Head to the official GitHub repository <a href="https://github.com/google/bundletool/releases">https://github.com/google/bundletool/releases</a></li><li>Download the latest <strong>bundletool-all-x.x.x.jar</strong> file.</li></ol><p>Example: bundletool-all-1.18.2.jar</p><p>3. Place the file in a known directory. For example:</p><pre>C:\bundletool\bundletool-all-1.18.2.jar</pre><h4>🔹 Step 2: Build APK Set from AAB</h4><p>Run this command:</p><pre>java -jar bundletool-all-1.18.2.jar build-apks \<br>  --bundle=PATH_TO_AAB\app-release.aab \<br>  --output=OUTPUT_PATH\app-release.apks \<br>  --mode=universal</pre><p>Key Flags Explained:</p><ul><li><strong>--bundle</strong> → Path to your .aab file.<br> <em>Example:</em> --bundle=C:\AndroidProjects\YourProject\build\outputs\app-release.aab</li><li><strong>--output</strong> → Path where the .apks archive will be generated.<br> <em>Example:</em> --output=C:\AndroidProjects\YourProject\build\outputs\app-release.apks</li><li><strong>--mode=default</strong> → Generates device-specific APKs for the connected device.</li><li><strong>--mode=universal</strong> → Creates a single APK with all resources (✅ best for quick testing/distribution).</li><li><strong>--mode=persistent</strong> → Generates the full APK set with splits (closest to how Play delivers apps).</li></ul><p>📌 <strong>Tip:</strong> For QA or sideloading on multiple devices, always use --mode=universal.</p><h4>🔹 Step 3: Extract the APK (Optional, only if you built multiple APKs within AAB)</h4><p>The generated file app-release.apks is actually a ZIP archive.<br>Rename and extract it:</p><p><strong>On Windows (CMD):</strong></p><pre>rename app-release.apks app-release.zip<br>tar -xf app-release.zip -C output_folder</pre><ul><li>rename → renames .apks to .zip.</li><li>tar -xf (available on Windows 10/11 by default) extracts the archive to output_folder.</li></ul><p><strong>On Linux/macOS:</strong></p><pre>mv app-release.apks app-release.zip<br>unzip app-release.zip -d output_folder</pre><h4>🔹 Step 4: Install APK on Device</h4><p>You can install directly using BundleTool without extracting:</p><pre>java -jar bundletool-all-1.18.2.jar install-apks --apks=app-release.apks</pre><p>Or, if you extracted a <strong>universal APK</strong>, install with adb:</p><pre>adb install output_folder/universal.apk</pre><h4>🔹 Step 5: Signing Considerations</h4><ul><li>If you’re using a <strong>release AAB</strong>, make sure it’s <strong>signed</strong> with your keystore before generating APKs.</li><li>Unsigned builds won’t install on physical devices unless you sign them manually with apksigner.</li></ul><h3>Common Errors &amp; Fixes</h3><pre>adb.exe: filename doesn&#39;t end .apk or .apex</pre><ol><li>If you got this error then you are doing wrong.<br>✅ Fix: You’re trying to install .apks directly. Use bundletool install-apks instead, or extract universal.apk.</li><li>Error: APK not signed <br>✅ Fix: Use your keystore with jarsigner or apksigner.</li><li>Device-Specific APK Missing Features<br>✅ Fix: Use --mode=universal to get a single full APK.</li></ol><p>If you encountered any other issues, please refer official documentation (<a href="https://developer.android.com/tools/bundletool">BundleTool</a>)</p><h3>Automating with Gradle</h3><p>Instead of manually typing commands, you can script it into your gradle.properties or CI/CD pipeline. Example for CI:</p><pre>java -jar bundletool-all-1.18.2.jar build-apks \<br>  --bundle=app-release.aab \<br>  --output=build/app-release.apks \<br>  --mode=universal \<br>  --ks=release.jks \<br>  --ks-key-alias=my-key \<br>  --ks-pass=pass:password \<br>  --key-pass=pass:password</pre><p>This ensures APKs are generated <strong>and signed automatically</strong>.</p><h3>Best Practices</h3><ul><li><strong>Use universal APK</strong> for testing or sideloading.</li><li><strong>Keep split APKs</strong> if you’re simulating Play Store delivery.</li><li><strong>Always test on multiple devices</strong> to ensure resources (localization, densities) are correct.</li><li><strong>Automate in CI/CD</strong> so QA teams don’t need manual commands.</li></ul><h3>Conclusion</h3><p>With <strong>BundleTool</strong>, you can seamlessly convert AABs into APKs for testing, sideloading, or QA distribution. By mastering these commands, you’ll save time and avoid common pitfalls when working with Google’s modern app delivery format.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=861dc382391f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android CI/CD using Bitbucket Pipelines + Deploy builds to Firebase App Distribution]]></title>
            <link>https://medium.com/@prathapkumar_l/android-ci-cd-using-bitbucket-pipelines-deploy-builds-to-firebase-app-distribution-4ab8f987c686?source=rss-356343077a19------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ab8f987c686</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[bitbucket-pipelines]]></category>
            <category><![CDATA[android-ci]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Prathap Kumar]]></dc:creator>
            <pubDate>Mon, 26 Sep 2022 09:12:18 GMT</pubDate>
            <atom:updated>2022-09-26T10:03:37.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*EtURa_eQkYFmAWCNI5Eh4g.png" /></figure><p>Automating anything nowadays is possible and makes our daily life easy.</p><p>In this article, we will learn how to automate the android application deployment process to the firebase app distribution using bitbucket pipelines. We will go through a step-by-step process to deploy an Android build (.apk file) to the firebase app distribution and distribute it to the testers. (Assuming that your project is already an existing repository in bitbucket).</p><p>Let&#39;s go through our 6 step process,</p><ol><li>Integrating Firebase App Distribution plugin into our android project.</li><li>Initialize the project as a firebase project using Firebase CLI.</li><li>Adding testers and release notes for the release.</li><li>Adding firebase token to bitbucket repository.</li><li>Getting KEY_FILE of the project from the google cloud console.</li><li>Setting up the pipeline configuration file (pipeline.yml)</li></ol><h4><strong>Step 1: </strong>Integrating Firebase App Distribution Plugin</h4><p>In your project-level Gradle file, add the App Distribution plugin as a buildscript dependency.</p><pre>// Top-level build file where you can add configuration options common to all sub-projects/modules.<br><br>buildscript <strong>{<br>    </strong>repositories <strong>{<br>        </strong>google()<br>        mavenCentral()<br>    <strong>}</strong></pre><pre><strong>    </strong>dependencies <strong>{<br>        </strong>classpath &#39;com.android.tools.build:gradle:7.1.2&#39;<br>        classpath &#39;com.google.firebase:firebase-appdistribution-gradle:3.0.3&#39;<br>    <strong>}<br>}</strong></pre><p>In your app-level Gradle file, include the App Distribution plugin below the Android plugin:</p><pre>apply plugin: &#39;com.android.application&#39;<br>apply plugin: &#39;com.google.firebase.appdistribution&#39;</pre><p>Sync your project after adding the plugin in both project-level and app-level Gradle files.</p><p>After successful sync, the firebase plugin tasks were added to our Gradle tasks list. You can check the tasks in the Gradle panel on the right or left of android studio.</p><blockquote>Look at <strong><em>app → Tasks → other → appDistribution tasks</em></strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*tiC65qwUOj08SJ-Pl1HwTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*97RmoUs2xXaO6Y-c57W42A.png" /></figure><h4>Step 2: Initialize the project as a firebase project using Firebase CLI</h4><p>Download the <a href="https://firebase.google.com/docs/cli#install-cli-windows">firebase-instant-tools-win.exe</a> from the link if you do not have installed already. Either you can install it through the npm or download a standalone binary package.</p><blockquote><strong><em>firebase login:ci</em></strong></blockquote><p>Using the above command in the Firebase CLI, log in to your firebase project and get the firebase refresh token which will be used to distribute to the firebase after the app is built.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/0*I1CjvG3SUJBhr-5M.jpeg" /></figure><p>Copy the token for later, as we save this FIREBASE_TOKEN in the bitbucket repository as an environmental variable.</p><p>Check for the <strong><em>.firebaserc</em></strong><em> </em>at the root location of your project. If the file does not exist your project is not initialized as a firebase project.</p><blockquote><strong><em>firebase init</em></strong></blockquote><p>Use the <strong>firebase init</strong> command and configure the project settings based on your needs.</p><p>After completion of the firebase project initialization, you can check the <strong><em>.firebaserc </em></strong>file at the root location of your project. Now the firebase project setup for your existing project is successful.</p><h4>Step 3: Adding Testers and Release notes</h4><p>Create 2 text files <strong>releasenotes.txt</strong> and <strong>testers.txt </strong>under the app folder. I recommend organizing your files based on the build types and flavors of your project. For example, I have created debug and release folders and created 2 files in each of the folders separately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*u-KVqi3QditLM7t44mlnYg.png" /></figure><p>Add the tester emails separated by a new line in the <strong><em>testers.txt</em></strong> file like below. Add your release notes to the <strong><em>releasenotes.txt</em></strong> file.</p><pre>someone@example.com<br>someone1@example.com<br>someone2@example.com</pre><p>Now add the firebaseAppDistrubtion property to the buildTypes in the app-level gradle file. Add the property to each build type that you want to build and deploy.</p><pre>buildTypes <strong>{<br><br>    </strong>debug <strong>{<br>        </strong>minifyEnabled false<br>        firebaseAppDistribution <strong>{<br>            </strong>releaseNotesFile = file(&#39;debug/releasenotes.txt&#39;)<br>            testersFile = file(&#39;debug/testers.txt&#39;)<br>        <strong>}<br>    }<br><br>    </strong>release <strong>{<br>        </strong>minifyEnabled true<br>        proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;</pre><pre>        firebaseAppDistribution <strong>{<br>            </strong>releaseNotesFile = file(&#39;release/releasenotes.txt&#39;)<br>            testersFile = file(&#39;release/testers.txt&#39;)<br>        <strong>}</strong><br>    <strong>}<br>}</strong></pre><p>Sync the project.</p><h4>Step 4: Adding firebase token to the bitbucket repository</h4><p>Add the FIREBASE_TOKEN that we saved earlier(in step 2) to the environment variables in the bitbucket repository settings.</p><p>Open Repository → Repository Settings → Repository Variables</p><p>Add a new variable by setting the name as FIREBASE_TOKEN and the value will be the firebase refresh token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*O0-OR1N2B8D0BrX724E__A.png" /></figure><p>We will use these variables in the pipeline script to authenticate the firebase project.</p><h4>Step 5: Getting KEY_FILE from the Google Cloud Console</h4><p>Log in to the <a href="https://console.cloud.google.com/">Google Cloud Console</a> and follow <a href="https://cloud.google.com/iam/docs/creating-managing-service-account-keys">these steps</a> to generate the KEY_FILE.</p><p>— — or — —</p><p>Before you begin, you need to enable the IAM API. Follow this <a href="https://console.cloud.google.com/flows/enableapi?apiid=iam.googleapis.com&amp;redirect=https://console.cloud.google.com&amp;_ga=2.71491731.1467074675.1664180197-672622824.1664180197">link</a> to enable it. After enabling the IAM API we need to create a service account key.</p><ol><li>In the Google Cloud console, go to the <a href="https://console.cloud.google.com/iam-admin/serviceaccounts?_ga=2.61982892.1467074675.1664180197-672622824.1664180197"><strong>Service accounts</strong></a> page.</li><li>Select a project.</li><li>On the <strong>Service accounts</strong> page, click the email address of the service account that you want to create a key to.</li><li>Click the <strong>Keys</strong> tab.</li><li>Click the <strong>Add key</strong> drop-down menu, then select <strong>Create new key</strong>.</li><li>Select <strong>JSON</strong> as the <strong>Key type</strong> and click <strong>Create</strong>.</li></ol><p>Clicking <strong>Create</strong> downloads a service account key file. After you download the key file, you cannot download it again.</p><p>The downloaded key has the following format, where PRIVATE_KEY is the private portion of the public/private key pair:</p><pre>{<br>  &quot;type&quot;: &quot;service_account&quot;,<br>  &quot;project_id&quot;: &quot;PROJECT_ID&quot;,<br>  &quot;private_key_id&quot;: &quot;KEY_ID&quot;,<br>  &quot;private_key&quot;: &quot;-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----\n&quot;,<br>  &quot;client_email&quot;: &quot;SERVICE_ACCOUNT_EMAIL&quot;,<br>  &quot;client_id&quot;: &quot;CLIENT_ID&quot;,<br>  &quot;auth_uri&quot;: &quot;https://accounts.google.com/o/oauth2/auth&quot;,<br>  &quot;token_uri&quot;: &quot;https://accounts.google.com/o/oauth2/token&quot;,<br>  &quot;auth_provider_x509_cert_url&quot;: &quot;https://www.googleapis.com/oauth2/v1/certs&quot;,<br>  &quot;client_x509_cert_url&quot;: &quot;https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL&quot;<br>}</pre><p>After downloading the KEY_FILE, encode the content to base64 string by using any online tool(<a href="https://codebeautify.org/json-to-base64-converter">Tool 1</a>, <a href="https://www.browserling.com/tools/json-to-base64">Tool 2</a>).</p><p>After encoding the string, save the string in the environment variables in the repository settings like the same thing we did for FIREBASE_TOKEN.</p><p>Also, add one more variable PROJECT_ID, with the value project id that you can find in the firebase project settings.</p><h4><strong>Step 6: Setting up the pipeline configuration file</strong></h4><p>First, we need to enable pipelines functionality in the Repository Settings → Pipelines → Settings → Enable Pipelines.</p><p>Create a bitbucket-pipelines.yml file at the root directory of the project and add the following code. Do some research on the pipeline&#39;s configuration and change the script according to the project&#39;s needs.</p><pre>image: androidsdk/android-30<br><br>pipelines:<br>  default:                <em># pipeline definition for all branches<br>        </em>- step:           <em># step to build Android debug application<br>            </em>name: Android Debug Application<br>            caches:       <em># caching speed up subsequent execution<br>              </em>- gradle<br>            script:<br>              - ./gradlew assembleDebug appDistributionUploadDebug<br>            artifacts:<br>              - app/build/outputs/**        <em># artifacts are files that are produced by a step<br>        </em>- step:<br>            name: Deploy to test<br>            deployment: test<br>            script:<br>              - pipe: atlassian/firebase-deploy:2.0.0<br>                variables:<br>                  KEY_FILE: $KEY_FILE<br>                  FIREBASE_TOKEN: $FIREBASE_TOKEN<br>                  PROJECT_ID: $PROJECT_ID</pre><p>Commit and push the files to the repository. Now you can see the pipeline is running and in progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OXEgDikgenIUJvNIcy7W-Q.png" /></figure><p>You can see the progress and status of the pipeline in the pipelines section of the repository. After successful completion of the pipeline, you can see the build(.apk file) uploaded to the firebase app distribution.</p><blockquote>NOTE: If you notice any error while running the pipeline like below.</blockquote><blockquote>.gradlew: Permission Denied</blockquote><blockquote>git update-index --chmod=+x gradlew</blockquote><blockquote>Run this command from the terminal and commit the changes. This updates the permission of the gradlew file.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwoFzX3wcHMhCmm-mgZ8uA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*98aVN6l09KvsYTB8Dnq5gw.png" /></figure><p>Congratulations, now you have successfully integrated android CI/CD using bitbucket pipelines.</p><p>Thank you for reading the article. ❤️🧡️💛</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ab8f987c686" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>