<?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 Prashant Dixit on Medium]]></title>
        <description><![CDATA[Stories by Prashant Dixit on Medium]]></description>
        <link>https://medium.com/@prashantdixit_87612?source=rss-f3c53b095310------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*q_snC5Z8wp46D33MwR0U-Q.jpeg</url>
            <title>Stories by Prashant Dixit on Medium</title>
            <link>https://medium.com/@prashantdixit_87612?source=rss-f3c53b095310------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:51:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prashantdixit_87612/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[Creating and publishing your own Android library in Kotlin — Maven Central Upload(2025) | Part-2]]></title>
            <link>https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-android-library-in-kotlin-maven-central-upload-2025-part-2-5c85818d20fd?source=rss-f3c53b095310------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c85818d20fd</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-libraries]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[maven-central]]></category>
            <dc:creator><![CDATA[Prashant Dixit]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 15:38:26 GMT</pubDate>
            <atom:updated>2025-11-30T18:05:41.257Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating and publishing your own Android library in Kotlin — Maven Central Upload(2025)| Part-2</h3><p>In the last article, we created our own Android library named <strong>Snacky</strong>. If you haven’t read the 1st part of the series, here is the <a href="https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-android-library-in-kotlin-2023-part-1-3e542dad4ca0"><strong>link</strong></a> to it. Now this article will focus on how to publish your library so other members of the open-source community can use it too. It’s your time to shine. So let’s begin.</p><p>There are various methods to make your library available to the public. The easiest method is to distribute the ‘.aar’ file, but the norm is publishing it to a publicly available Maven repository. The reason is simple: let’s say you find a bug or want to update your library, then it is a nightmare. That’s where Maven comes in.</p><p>For publishing your libraries publicly, numerous repositories and hosting services are available. The simplest option is <strong>JitPack</strong>, which may not offer extensive customization or control, but it is quite straightforward to set up. Publish your project on GitHub, and JitPack should be able to create and distribute it immediately. If you’re new to libraries, this is an excellent way to get your code out there. Then there were Bintray and Jcenter, which have now stopped accepting new packages.</p><p>And finally, with <a href="https://central.sonatype.org/pages/ossrh-eol/"><strong>OSSRH</strong></a> Sonatype Jira officially shutting down on <strong>June 30th, 2025</strong>, Maven Central is now the recommended place to publish your libraries. If your workflow relies on Maven, this is where you should be. Artifacts on <strong>Maven Central</strong> are highly trusted, and their integrity is guaranteed as the author signs every release.</p><p>In this article, we’ll publish a library to Maven Central using the <strong>Upload</strong> method. It might look a bit complicated at first, but don’t worry — you only need to set things up once. After that, deploying new versions is basically just running a couple of commands in your terminal. Okay!! Enough chit-chat, buckle up, and let’s get to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*HKg5X-eSAKRkyPmXNOGDSQ.gif" /></figure><h3>1. Registering Your Namespace on Maven Central</h3><p>Before you can publish your library to Maven Central, you need to register and verify a <a href="https://central.sonatype.org/register/namespace/"><strong>namespace</strong></a>. Think of a namespace as your unique address on Maven Central — it ensures that only you can publish libraries under that specific domain. This prevents conflicts and guarantees that when someone downloads <em>com.yourcompany.awesomelib</em>, they’re getting your authentic library, not someone else’s.</p><p>The verification process proves you own the domain or GitHub account you’re claiming, which adds a crucial security layer to the Maven ecosystem. The registration process is straightforward: you’ll create an account on Maven Central’s portal, claim your namespace (either using your GitHub username or a custom domain), and verify ownership through a simple validation step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*0JL92wmP_ViigE7kaixf9g.png" /></figure><h4>1.1 Sign In Using GitHub (Fastest Method)</h4><p>The fastest way to get started with Maven Central is to sign up with your GitHub account. When you register using GitHub, you automatically receive a verified namespace in the format <em>io.github.&lt;your-github-username&gt;</em>. This eliminates the manual verification step since Maven Central trusts GitHub’s domain ownership.</p><p>Here’s how to do it:</p><p>1. Go to <a href="https://central.sonatype.com/">https://central.sonatype.com</a> and click <strong>Sign Up</strong></p><p>2. Choose <strong>Continue with GitHub</strong> and authorize the Maven Central application</p><p>3. Your namespace <em>io.github.&lt;your-username&gt;</em> will be automatically created and verified</p><p>4. You can immediately start publishing libraries under this namespace</p><blockquote><strong>Note:</strong> This method only works for your personal GitHub username, not organization accounts. If you need an organization namespace like io.github.&lt;organization-name&gt;, you’ll need to contact Central Support.</blockquote><h4>1.2 Verifying a Namespace via Code Hosting Services</h4><p>If you already have a Maven Central account (maybe you signed up with email or Google) or you are a new user, and want to use a namespace without owning a domain, this method is for you. You can claim namespaces like <em>io.github.yourusername</em>, <em>io.gitlab.yourusername</em>, or <em>io.bitbucket.yourusername</em> by proving you own the respective account. Here’s how it works:</p><p>1. Go to Maven Central, sign up or log in using “Continue with Google” and request your desired namespace (like io.github.yourusername)</p><p>2. Maven Central gives you a verification key — a random string you’ll use as a repository name</p><p>3. Create a public repository on GitHub (or GitLab/Bitbucket) using that verification key as the repo name</p><p>4. Submit the repository URL back to Maven Central</p><p>5. Once verified, you can delete the temporary repository</p><p>This works with <strong>GitHub</strong>, <strong>GitLab</strong>, <strong>Gitee</strong>, and <strong>Bitbucket</strong>. Each gives you a different namespace format (io.github.*, io.gitlab.*, etc.). It’s perfect for developers who want a clean, recognizable namespace but don’t want to purchase and manage a custom domain. You can read more about this method <a href="https://central.sonatype.org/register/namespace/#for-code-hosting-services-with-personal-groupid"><strong>here</strong></a>.</p><h4>1.3 Verifying a Custom Domain Using DNS TXT Record</h4><p>This method is for developers who <strong>own a custom domain</strong> and want to use it as their namespace (like <em>com.yourcompany</em> or <em>org.yourproject</em>). You prove ownership by adding a special DNS record that Maven Central can verify.</p><p>For this article, we won’t delve deep into this method. You can follow the detailed steps in the official Maven Central namespace <a href="https://central.sonatype.org/register/namespace/#by-dns"><strong>documentation</strong></a> to verify your custom domain.</p><p>This approach provides the most professional-looking namespace and works great if you already have a website or business domain. Most domain providers (GoDaddy, Namecheap, Cloudflare) make adding TXT records simple through their control panels.</p><h3>2. Preparing Your Android Library for Publishing</h3><p>Congratulations! You’ve successfully registered your namespace on Maven Central — that’s a big step towards becoming a published library author. Now comes the exciting part: getting your Android library module ready for Maven Central’s <a href="https://central.sonatype.org/publish/publish-portal-upload/"><strong>upload-based</strong></a> publishing system.</p><p>We’ll configure your project files to generate all the artifacts that Maven Central requires for manual upload. This approach uses<br> Maven Central’s new bundle upload feature, where you create a complete package locally and upload it through their web portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*-rNiPOBfjR_Vm1X5Mnoo5w.gif" /></figure><h4>2.1 Creating the Publishing Script (scripts/publish-module.gradle)</h4><p>First, we need to create a <strong>reusable publishing script</strong> that handles all the Maven publication logic. This keeps our library’s build.gradle clean and makes it easy to apply the same publishing setup to multiple modules.</p><p><strong>Create the file structure:</strong><br> 1. In your library module folder (e.g., Snacky/), create a new directory called <strong>scripts</strong><br> 2. Inside <strong>scripts</strong>/, create a file named <strong>publish-module.gradle</strong></p><p>Here’s the complete code:</p><pre>/**<br> * Lightweight Maven Central publish script for Gradle &gt;8<br> * Works with Android libraries.<br> */<br><br>apply plugin: &#39;maven-publish&#39;<br>apply plugin: &#39;signing&#39;<br><br>afterEvaluate {<br>    publishing {<br>        publications {<br>            release(MavenPublication) {<br>                from components.release<br><br>                groupId project.ext.PUBLISH_GROUP_ID<br>                artifactId project.ext.PUBLISH_ARTIFACT_ID<br>                version project.ext.PUBLISH_VERSION<br><br>                pom {<br>                    name = project.ext.PUBLISH_ARTIFACT_ID<br>                    description = &#39;A custom snackbar library for android&#39;<br>                    url = &#39;https://github.com/prashant564/CustomSnackbar&#39;<br>                    licenses {<br>                        license {<br>                            name = &#39;The Apache License, Version 2.0&#39;<br>                            url = &#39;http://www.apache.org/licenses/LICENSE-2.0.txt&#39;<br>                        }<br>                    }<br>                    developers {<br>                        developer {<br>                            id = &#39;prashant564&#39;<br>                            name = &#39;Prashant Dixit&#39;<br>                            email = &#39;prashant.dixit@hotmail.com&#39;<br>                        }<br>                    }<br>                    scm {<br>                        connection = &#39;scm:git:github.com/prashant564/CustomSnackbar.git&#39;<br>                        developerConnection = &#39;scm:git:ssh://github.com/prashant564/CustomSnackbar.git&#39;<br>                        url = &#39;https://github.com/prashant564/CustomSnackbar/tree/main&#39;<br>                    }<br>                }<br>            }<br>        }<br>    }<br><br>    signing {<br>        // The signing plugin will automatically use properties like signing.keyId, <br>        // signing.password, and signing.secretKeyRingFile if they are present in the<br>        // project&#39;s extra properties. They are loaded from local.properties by the root build.gradle.<br>        sign publishing.publications<br>    }<br>}</pre><p>Key points about this script:<br>1)- <strong>afterEvaluate</strong> prevents the “unknown property ‘<strong>release</strong>’” error by waiting for the Android plugin to create components<br>2)- <strong>POM metadata</strong> includes all the required information Maven Central needs for validation<br>3)- <strong>Signing block</strong> automatically uses GPG credentials (we’ll set these up later)<br>4)- Publication name “<strong>release</strong>” uses the release variant of your Android library</p><blockquote>Remember to customize the POM section with your own project details — name, description, GitHub URLs, and developer information.</blockquote><h4>2.2 Adding Publish Metadata in build.gradle (Library Module)</h4><p>Now we need to configure your library’s <strong>build.gradle</strong> to work with our publishing script. There are three key changes to make:</p><ol><li><strong>Add the Maven coordinates in an ext block (below the plugins block):</strong></li></ol><pre>ext {<br>    PUBLISH_GROUP_ID = &#39;io.github.prashant564&#39;<br>    PUBLISH_VERSION = &#39;1.0.0&#39;<br>    PUBLISH_ARTIFACT_ID = &#39;snacky&#39;<br>}</pre><p>These three values create your library’s <strong>Maven coordinates</strong> — like a postal address for your library:<br> — <strong>PUBLISH_GROUP_ID</strong>: Your namespace (use the one you registered on Maven Central)<br> — <strong>PUBLISH_ARTIFACT_ID</strong>: Your library’s name (what developers will type to import it)<br> — <strong>PUBLISH_VERSION</strong>: The version number of your library (start with 1.0.0)</p><p><strong>2. Apply the publishing script:</strong></p><p>Add this line below the ext block we created in the above step:</p><pre>apply from: &quot;${rootDir}/Snacky/scripts/publish-module.gradle&quot;</pre><p>This line connects our publishing script to your library module. Make sure the path matches your actual module name and folder structure.</p><p>3. Add this code snippet inside the <strong>android</strong> block:</p><pre>android {<br>   // … your existing configuration …<br>    publishing {<br>     singleVariant(&#39;release&#39;) {<br>       withSourcesJar()<br>       withJavadocJar()<br>     }<br>   }<br> }</pre><p>This tells the Android Gradle Plugin to automatically generate <strong>source</strong> and <strong>Javadoc JARs </strong>for the release variant. Maven Central requires this modern approach to prevent common build errors related to duplicate tasks.</p><h4>2.3 Updating Root build.gradle for Signing Credentials</h4><p>The <strong>root-level</strong> build.gradle needs to handle GPG signing credentials securely. For simplicity, we’ll store them in local.properties (though environment variables and other methods are also available).</p><p><strong>Add this code to your root build.gradle:</strong></p><pre>allprojects {<br>    def localPropertiesFile = rootProject.file(&#39;local.properties&#39;)<br>    if (localPropertiesFile.exists()) {<br>        def localProperties = new Properties()<br>        localPropertiesFile.withReader(&#39;UTF-8&#39;) { reader -&gt;<br>            localProperties.load(reader)<br>        }<br>        localProperties.each { key, value -&gt;<br>            ext.set(key, value)<br>        }<br>    }<br>}</pre><p>This script reads GPG credentials from <strong>local.properties</strong> and makes them available to all modules. We’ll create this file and add the signing credentials in the next section.</p><h4>2.4 Creating the Bundle Generation Script (prepare-maven-central.sh)</h4><p>Finally, we need an automation script that builds your library and packages everything into a single bundle for Maven Central Upload. This script handles the entire build process and creates the required checksums.</p><p><strong>Create a file named prepare-maven-central.sh in your project root:</strong></p><pre>#!/bin/bash<br>set -e<br><br># ---------------------------------------------<br># Colors<br># ---------------------------------------------<br>GREEN=&quot;\033[1;32m&quot;<br>BLUE=&quot;\033[1;34m&quot;<br>YELLOW=&quot;\033[1;33m&quot;<br>CYAN=&quot;\033[1;36m&quot;<br>RED=&quot;\033[1;31m&quot;<br>NC=&quot;\033[0m&quot; # reset<br><br>echo -e &quot;${CYAN}&quot;<br>echo &quot;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━&quot;<br>echo &quot;     📦 Snacky – Maven Central Prep Tool&quot;<br>echo &quot;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━&quot;<br>echo -e &quot;${NC}&quot;<br><br># ---------------------------------------------<br># Load publish config<br># ---------------------------------------------<br>MODULE_NAME=&quot;snacky&quot;<br>GROUP_ID=&quot;io/github/prashant564&quot;<br>ARTIFACT_ID=&quot;snacky&quot;<br><br>VERSION=$(grep &quot;PUBLISH_VERSION&quot; Snacky/build.gradle | cut -d&quot;&#39;&quot; -f2)<br><br>if [ -z &quot;$VERSION&quot; ]; then<br>  echo -e &quot;${RED}❌ ERROR: Could not find PUBLISH_VERSION in Snacky/build.gradle${NC}&quot;<br>  exit 1<br>fi<br><br>echo -e &quot;${GREEN}✔ Version found: ${VERSION}${NC}&quot;<br><br># ---------------------------------------------<br># Cleanup old build<br># ---------------------------------------------<br>TARGET_DIR=&quot;maven-build&quot;<br>echo -e &quot;${BLUE}🧹 Cleaning old directory ${TARGET_DIR}${NC}&quot;<br>rm -rf &quot;$TARGET_DIR&quot;<br>mkdir -p &quot;$TARGET_DIR&quot;<br><br># ---------------------------------------------<br># Run Gradle build + generate POM + Jars<br># ---------------------------------------------<br>echo -e &quot;${YELLOW}🚀 Building release artifacts...${NC}&quot;<br>./gradlew clean assembleRelease publishReleasePublicationToMavenLocal<br><br>LOCAL_M2=&quot;$HOME/.m2/repository/$GROUP_ID/$ARTIFACT_ID/$VERSION&quot;<br>if [ ! -d &quot;$LOCAL_M2&quot; ]; then<br>  echo -e &quot;${RED}❌ ERROR: Expected Maven local directory not found:&quot;<br>  echo &quot;$LOCAL_M2&quot;<br>  exit 1<br>fi<br><br>echo -e &quot;${GREEN}✔ Artifacts generated in Maven Local${NC}&quot;<br><br># ---------------------------------------------<br># Copy to staging folder<br># ---------------------------------------------<br>DEST=&quot;$TARGET_DIR/$GROUP_ID/$ARTIFACT_ID/$VERSION&quot;<br>mkdir -p &quot;$DEST&quot;<br><br>echo -e &quot;${BLUE}📁 Copying final artifacts...${NC}&quot;<br>cp &quot;$LOCAL_M2&quot;/* &quot;$DEST&quot;/<br><br>echo -e &quot;${GREEN}✔ Files copied to: ${DEST}${NC}&quot;<br><br># ---------------------------------------------<br># Generate Checksums (md5, sha1)<br># ---------------------------------------------<br>echo -e &quot;${BLUE}⚙️  Generating checksums...${NC}&quot;<br>pushd &quot;$DEST&quot; &gt; /dev/null<br>for f in *.aar *.jar *.pom *.module; do<br>  if [ -f &quot;$f&quot; ]; then<br>    md5 -q &quot;$f&quot; &gt; &quot;$f.md5&quot;<br>    shasum -a 1 &quot;$f&quot; | awk &#39;{print $1}&#39; &gt; &quot;$f.sha1&quot;<br>  fi<br>done<br>popd &gt; /dev/null<br>echo -e &quot;${GREEN}✔ Checksums generated.${NC}&quot;<br><br><br># ---------------------------------------------<br># Create upload ZIP<br># ---------------------------------------------<br>ZIP_NAME=&quot;${ARTIFACT_ID}-${VERSION}-bundle.zip&quot;<br>echo -e &quot;${YELLOW}📦 Creating ZIP bundle: ${ZIP_NAME}${NC}&quot;<br><br>cd &quot;$TARGET_DIR&quot;<br>zip -r &quot;../${ZIP_NAME}&quot; . &gt; /dev/null<br>cd ..<br><br>echo -e &quot;${GREEN}✔ ZIP created: ${ZIP_NAME}${NC}&quot;<br><br>echo -e &quot;${CYAN}&quot;<br>echo &quot;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━&quot;<br>echo &quot;🚀 NEXT STEPS: PUBLISH TO MAVEN CENTRAL&quot;<br>echo &quot;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━&quot;<br>echo -e &quot;${NC}&quot;<br><br>echo -e &quot;${BLUE}1.${NC} Go to: https://central.sonatype.com/publishing&quot;<br>echo -e &quot;${BLUE}2.${NC} Click ${GREEN}“Publish Component”${NC}&quot;<br>echo -e &quot;${BLUE}3.${NC} Upload file: ${YELLOW}${ZIP_NAME}${NC}&quot;<br>echo &quot;&quot;<br>echo -e &quot;${GREEN}✨ Your Snacky library will be published after validation!${NC}&quot;<br>echo &quot;&quot;</pre><blockquote><strong>What this script does:</strong><br> — Builds your library and publishes all artifacts to local Maven repository (~/.m2)<br> — Generates required checksums (MD5 and SHA1) for all files — Maven Central needs these for validation<br> — Creates a complete bundle with all artifacts, signatures, and checksums in a single ZIP file<br> — Places the bundle on your Desktop ready for upload</blockquote><h3>3. Setting Up GPG Signing (Required for Maven Central)</h3><p>Maven Central requires <strong>all uploaded artifacts to be digitally signed</strong> using <strong>GPG</strong> (GNU Privacy Guard) to guarantee their authenticity and integrity. This ensures that when developers download your library, they can trust it hasn’t been tampered with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*FD7DDh0MTDHv3Gahl_SszA.gif" /></figure><p>Don’t worry if you’ve never used GPG before — it’s essentially creating a digital signature that proves you’re the real author. We’ll walk through the process of installing GPG, generating your signing key, and configuring it for use with your build scripts.</p><h4>3.1 Installing GPG</h4><p>First, you need to install GPG on your system to create and manage signing keys.</p><p><strong>For macOS (recommended):</strong></p><pre>brew install - cask gpg-suite</pre><p><strong>Other options:</strong><br> — Windows: Download from <a href="https://gnupg.org/download/">https://gnupg.org/download/</a><br> — Linux: Usually pre-installed, or use sudo apt install gnupg (Ubuntu/Debian)<br> — Alternative for all platforms: Download from the official GnuPG website</p><p>Create a new GPG key pair for signing your library releases:</p><pre>gpg --full-generate-key</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*uoG8332lwKdMd-036W_7wg.png" /></figure><p>Follow the prompts:<br> 1. Key type: Choose RSA and RSA (default)<br> 2. Key size: Enter <strong>4096</strong> bits for maximum security<br> 3. Expiration: Choose <strong>1y</strong> (1 year) or <strong>0</strong> (no expiration)<br> 4. Real name &amp; Email: Use the same details as mentioned in your library<br> 5. Passphrase: Create a strong passphrase — you’ll need this later</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-foNKGCpaQdL1oNoOU5LQ.png" /></figure><p>Once all the above steps are complete, you will see the generated <strong>RSA4096</strong> key.</p><h4>3.3 Exporting the ASCII-Armored Private Key</h4><p>First, find your key ID:</p><pre>gpg --list-secret-keys --keyid-format=long</pre><p>If you’ve followed the above steps correctly, then you should see this output with your key details. Look for the 16-character ID after <strong>rsa4096/ </strong>in the<strong> sec </strong>line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*de2j4SZARc_e5Ts5w3BJXA.png" /></figure><p>Export your private key (replace <strong>&lt;Your_Key_ID&gt;</strong> with the full 16-character ID). Run the following command at the root level of your project so that Gradle can use the newly created <strong>signing.gpg</strong> file there.</p><pre>gpg --export-secret-keys -o signing.gpg &lt;Your_Key_ID&gt;</pre><h4>3.4 Adding Signing Credentials to local.properties</h4><p>Create or edit <strong>local.properties</strong> in your project root and add:</p><pre>signing.keyId=&lt;LAST_8_CHARS_OF_KEY_ID&gt;<br>signing.password=&lt;YOUR_PASSPHRASE&gt;<br>signing.secretKeyRingFile=&quot;absolute/path/to/signing.gpg&quot;</pre><p><strong>Replace with your actual values:</strong><br> — <strong>signing.keyId</strong>: Use only the last 8 characters of your 16-character key ID<br> — <strong>signing.password</strong>: The passphrase you created when generating the key<br> — <strong>signing.secretKeyRingFile</strong>: The filename of your exported key file</p><h4>3.5 Verifying the Signing Setup</h4><p>Add these files to your <strong>.gitignore</strong> to keep credentials secure. It’s crucial never to push files containing secrets to GitHub, as they can be used for malicious purposes.</p><pre>// rest of code<br><br>local.properties<br>signing.gpg</pre><p>Lastly, upload your <strong>GPG public key</strong> to a key server so Maven Central can verify signatures during the <strong>validation</strong> phase of library deployment. Run the following command:</p><pre>gpg --keyserver keyserver.ubuntu.com --send-keys &lt;Your_16_Char_Key_ID&gt;</pre><p>If you’ve followed all the steps correctly until now, your folder structure should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*bImFI7unfjRLjLVUPsdZkw.png" /></figure><h3>4. Building the Bundle and Publishing to Maven Central</h3><p>We’re almost there! With all the configuration in place, it’s time to build our library artifacts and upload them to Maven Central using their new <strong>bundle upload system</strong>. This final step will make our library available to developers worldwide.</p><p>The process involves running our automation script to generate all required files, then using Maven Central’s web portal to upload and publish the bundle. Let’s get your library published!</p><h4>4.1 Running the Bundling Script</h4><p>Now it’s time to generate our library bundle with all the required artifacts, signatures, and checksums. Run the following command at the <strong>project root</strong> level:</p><pre>bash prepare-maven-central.sh</pre><p><strong>Here’s a step-by-step guide of what happens when we run our script:</strong><br> 1. <strong>Clean build</strong> — Removes any previous build artifacts<br> 2. <strong>Assembles release AAR</strong> — Creates your library’s main artifact<br> 3. <strong>Generates sources and Javadoc JARs</strong> — Required by Maven Central<br> 4. <strong>Signs all artifacts</strong> — Uses your GPG key to sign everything<br> 5. <strong>Creates checksums</strong> — Generates MD5 and SHA1 files for validation<br> 6. <strong>Bundles everything</strong> — Packages all files into maven-central-bundle.zip</p><p>If you’ve followed all the steps correctly, you will see the following terminal output, and a bundled zip file will be created at the project root level, ready to be uploaded to Maven Central.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBaho4aeKw7SprOWDrI15w.png" /></figure><p>If there are errors, check:<br> — Your <strong>GPG</strong> credentials in <strong>local.properties</strong><br> — The <strong>signing.gpg</strong> file exists<br> — Your library’s namespace in the ext block matches your registered namespace</p><p>Give yourself a pat on the back if you’ve reached this point. We are now just a couple of small steps away from publishing our very first Android library.</p><h4>4.2 Uploading the Bundle to the Central Portal</h4><p>With your bundle ready, it’s time to upload it to Maven Central’s web portal.</p><p>Steps to upload:<br> 1. Go to <a href="https://central.sonatype.com/publishing">https://central.sonatype.com/publishing</a>, and you should see a <strong>Publish Component</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*455lB0kSykVt0lO-uiUznw.png" /></figure><p>2. Click <strong>Publish Component</strong> in the dashboard, and a pop-up will appear where you will see the <strong>Deployment Name</strong> and <strong>Description</strong> text boxes and an <strong>Upload Your File </strong>option. Select your bundled zip and wait for upload completion. Once uploaded, click <strong>Publish Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wk1-A8V9YL1abqGy0LE0Ew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XlpwAJwTaULBqaPIJfQE5A.png" /></figure><p>Once we hit <strong>Publish Component</strong>, the portal will start validating our bundled zip, and you should see this screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UuQjau0WrdqjIXvwbpzXg.png" /></figure><p>What the portal validates:<br> — All required artifacts are present (AAR, sources JAR, Javadoc JAR, POM)<br> — GPG signatures are valid and match your uploaded public key<br> — Checksums are correct for all files<br> — POM metadata meets Maven Central requirements</p><p>If there are errors, the portal displays specific issues to fix — usually related to missing signatures or incorrect POM metadata.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYCQYvvD_tLkN46X2YPa9Q.png" /></figure><p>If validation passes, you’ll see a <strong>Validated</strong> status, which means your bundle follows Maven Central’s rules and is ready to be published for other developers to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f14Eu3IGKJvAlSnWXeDxoQ.png" /></figure><h4>4.3 Validating and Releasing Your Library</h4><p>Once uploaded and validated, we’re ready for the final step — making our library publicly available. Click on <strong>Publish </strong>and confirm the publication. Keep in mind, this step is irreversible. You will now see the library in <strong>Publishing</strong> status, and it usually takes 10–30 minutes to process the release and make it live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkm3AJJuSPbuerTvd8Oq_A.png" /></figure><p>Once the processing is done and the library is live on <strong>Maven</strong>, the status of your deployment will change to<strong> Published.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Egp7WB7N6-ftVwTcoIkj0g.png" /></figure><p>🎉 Congratulations! Our library is now live on Maven Central. We can look for our library on <a href="https://search.maven.org/">https://search.maven.org</a>. Developers can add it to their projects using:</p><pre>implementation &#39;io.github.prashant564:snacky:1.0.0&#39;</pre><p>For future updates, we increment our version number in the ext block and rerun the bundle script!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*FPFn2_MISojeNpp2hwv8yg.gif" /></figure><h3>Conclusion</h3><p>Well done! We’ve successfully walked through the complete process of publishing an Android library to Maven Central using the modern<br> bundle upload method. From registering our namespace and configuring build scripts to setting up GPG signing and creating automated bundling scripts, we’ve transformed a regular Android library into a professionally published artifact that millions of developers can now discover and use in their projects.</p><p>This article focused on Maven Central’s <strong>bundle upload method</strong>, which provides excellent control and visibility for library authors. While perfect for getting started, our upcoming articles will explore advanced automated methods like the <a href="https://central.sonatype.org/publish/publish-portal-api/"><strong>Publisher API</strong></a> and direct <a href="https://central.sonatype.org/publish/publish-portal-gradle/"><strong>Gradle</strong></a> integration that enable seamless CI/CD workflows.</p><p>You can find the source code of this project on my GitHub. Here is the GitHub repository <a href="https://github.com/prashant564/CustomSnackbar"><strong>link</strong></a>.</p><p>We’ve taken an important step in contributing to the open-source ecosystem — Welcome to the community of published library authors!🥳🎊</p><p>Thank you for reading this article and following me for upcoming articles related to app development. Please give a clap if you found this article useful. Happy learning😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c85818d20fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating and publishing your own iOS library in Swift(2024) | Part 2]]></title>
            <link>https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-ios-library-in-swift-2024-part-2-368c612d8ca5?source=rss-f3c53b095310------2</link>
            <guid isPermaLink="false">https://medium.com/p/368c612d8ca5</guid>
            <dc:creator><![CDATA[Prashant Dixit]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 20:48:20 GMT</pubDate>
            <atom:updated>2024-04-30T20:48:20.406Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last article, we created our own iOS library named Snacky. If you haven’t read the 1st part of the series, here is the <a href="https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-ios-library-in-swift-2024-part-1-4dd8b211802a">link</a> to it. Now this article will focus on how to publish your library so other members of the open-source community can use it too. It’s your time to shine. So let’s begin.</p><p>We will publish our library on CocoaPods, a handy tool for iOS and macOS developers. It simplifies managing external code libraries by automating tasks like downloading and integrating dependencies. With CocoaPods, developers can keep their projects organized and efficient with minimal effort.</p><p>Now that we know a good platform to publish our library. So grab your coffee and let’s start the publishing process without further ado.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F21379254&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcoding-gif-21379254&amp;image=https%3A%2F%2Fmedia.tenor.com%2FhCA2Sd0NIvIAAAAF%2Fcoding.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/f445367cc3580b76dc8d865e65179af5/href">https://medium.com/media/f445367cc3580b76dc8d865e65179af5/href</a></iframe><p><strong>Step 1: Bumping up the library version and modify .podspec file</strong></p><p>As you develop your library and implement changes, each new version captures your library&#39;s state at a specific moment. Increasing the version number is a marker for developers who rely on your library, indicating the modifications made since their last update. This process enables them to make informed decisions about whether to integrate the latest changes into their projects. It’s akin to assigning a label to each iteration of your library, facilitating tracking of updates for users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*0KeBi3eVSUqKTHXXgoyOUQ.png" /></figure><p>Click on <strong>Snacky.podspec</strong> file and open it. The Podspec file defines the metadata and configuration for the pod, allowing CocoaPods to manage its integration into projects effectively. Now let’s go through the important fields that we need to be aware of in this file. Initially the podspec file looks like this.</p><pre>Pod::Spec.new do |s|<br>  s.name             = &#39;Snacky&#39;<br>  s.version          = &#39;0.1.0&#39;<br>  s.summary          = &#39;A short description of Snacky.&#39;<br><br># This description is used to generate tags and improve search results.<br>#   * Think: What does it do? Why did you write it? What is the focus?<br>#   * Try to keep it short, snappy and to the point.<br>#   * Write the description between the DESC delimiters below.<br>#   * Finally, don&#39;t worry about the indent, CocoaPods strips it!<br><br>  s.description      = &lt;&lt;-DESC<br>TODO: Add long description of the pod here.<br>                       DESC<br><br>  s.homepage         = &#39;https://github.com/prashant564/Snacky&#39;<br>  # s.screenshots     = &#39;www.example.com/screenshots_1&#39;, &#39;www.example.com/screenshots_2&#39;<br>  s.license          = { :type =&gt; &#39;MIT&#39;, :file =&gt; &#39;LICENSE&#39; }<br>  s.author           = { &#39;prashant564&#39; =&gt; &#39;prashantdixit600@gmail.com&#39; }<br>  s.source           = { :git =&gt; &#39;https://github.com/prashant564/Snacky.git&#39;, :tag =&gt; s.version.to_s }<br>  # s.social_media_url = &#39;https://twitter.com/&lt;TWITTER_USERNAME&gt;&#39;<br><br>  s.ios.deployment_target = &#39;10.0&#39;<br><br>  s.source_files = &#39;Snacky/Classes/**/*&#39;<br>  <br>  # s.resource_bundles = {<br>  #   &#39;Snacky&#39; =&gt; [&#39;Snacky/Assets/*.png&#39;]<br>  # }<br><br>  # s.public_header_files = &#39;Pod/Classes/**/*.h&#39;<br>  # s.frameworks = &#39;UIKit&#39;, &#39;MapKit&#39;<br>  # s.dependency &#39;AFNetworking&#39;, &#39;~&gt; 2.3&#39;<br>end</pre><ul><li>s.name: Specifies the name of the pod. In this case, it&#39;s set to &#39;Snacky&#39;.</li><li>s.version: Specifies the version number of the pod. Here, it&#39;s set to &#39;0.1.0&#39;. Since this is our first release we’ll not bump up the version. In the next release, for example, we’ll bump it up to ‘0.1.1’.</li><li>s.summary: Provides a brief description of the pod. It&#39;s intended to be short, snappy, and to the point. We will modify this and write a summary of our own.</li><li>s.description: Provides a longer description of the pod. This field allows for a more detailed explanation of the pod&#39;s functionality and purpose. We will modify this and write a summary of our own.</li><li>s.homepage: Specifies the URL where users can find more information about the pod, such as documentation or additional resources.</li><li>s.license: Indicates the license under which the pod is distributed. It includes the type of license (e.g., MIT) and the file where the license text can be found.</li><li>s.author: Specifies the author(s) of the pod along with their contact information.</li><li>s.source: Specifies the source code repository for the pod, including the Git URL and the tag (version) of the repository to use.</li><li>s.ios.deployment_target: Specifies the minimum iOS version required for the pod to work. Here, it&#39;s set to &#39;10.0&#39;. In the previous article while building our project, we set the Minimum Deployments to iOS 13.0, so here we’ll modify this value and set it to ‘13.0’</li><li>s.source_files: Specifies the files to include from the source directory when integrating the pod into a project. In this case, it includes all files under &#39;Snacky/Classes/&#39; directory and its subdirectories.</li></ul><p>Here is the updated Snacky.podspec file after the modifications.</p><pre><br>Pod::Spec.new do |s|<br>  s.name             = &#39;Snacky&#39;<br>  s.version          = &#39;0.1.0&#39;<br>  s.summary          = &#39;Snacky is a library that allows users to create and show custom UIAlerts.&#39;<br><br><br>  s.description      = &quot;Snacky is an iOS library which allows users to build customizable, dynamic UIAlerts easily.&quot;<br><br>  s.homepage         = &#39;https://github.com/prashant564/SnackyIOS&#39;<br>  # s.screenshots     = &#39;www.example.com/screenshots_1&#39;, &#39;www.example.com/screenshots_2&#39;<br>  s.license          = { :type =&gt; &#39;MIT&#39;, :file =&gt; &#39;LICENSE&#39; }<br>  s.author           = { &#39;prashant564&#39; =&gt; &#39;prashantdixit600@gmail.com&#39; }<br>  s.source           = { :git =&gt; &#39;https://github.com/prashant564/SnackyIOS.git&#39;, :tag =&gt; s.version.to_s }<br>  # s.social_media_url = &#39;https://twitter.com/&lt;TWITTER_USERNAME&gt;&#39;<br><br>  s.ios.deployment_target = &#39;13.0&#39;<br>  s.swift_version = &#39;4.1&#39;<br><br>  s.source_files = &#39;Snacky/Classes/**/*&#39;<br>  <br>  # s.resource_bundles = {<br>  #   &#39;Snacky&#39; =&gt; [&#39;Snacky/Assets/*.png&#39;]<br>  # }<br><br>  # s.public_header_files = &#39;Pod/Classes/**/*.h&#39;<br>  # s.frameworks = &#39;UIKit&#39;, &#39;MapKit&#39;<br>  # s.dependency &#39;AFNetworking&#39;, &#39;~&gt; 2.3&#39;<br>end</pre><blockquote>Important Note: Always remember to bump up the value of <strong>s.version </strong>at the time of new release.</blockquote><h4>Step 2: Pushing changes to GitHub and adding tags</h4><p>Once all your code changes are done, and you’ve bumped up the library version in podspec file, we’ll now push our changes to Github and add a tag with the same version number as we have mentioned in the podspec file. This will ensure consistency and clarity in version management for your library.</p><ul><li>First, we push our latest commits to git.</li></ul><pre>git push origin main</pre><ul><li>Next, we add a tag with the same version number as the Podspec file. Currently, the version number in the Podspec file is ‘0.1.0’, so we’ll use the same value for the Git tag.</li></ul><pre>git tag &#39;0.1.0&#39;</pre><ul><li>Push the newly created tag to GitHub</li></ul><pre>git push origin --tags</pre><p>Good job, till now we have updated our podspec file, created a new git tag, and pushed all our code and tags to Github. Now in the next sections, we get to deploying our library to Cocoapods.</p><h4>Step 3: Publishing our library</h4><p>There are two types of pods. Private pods and public pods. Currently, we’re creating a public pod that can be used by everyone in the open-source community and it allows collaboration. Private pods are mostly used by organizations for internal products and code management.</p><p>The focus of this article is to teach you how to publish a public pod but in case you’re interested in publishing a private pod, I’ll mention some good resources and articles to check out. With all that said, let’s start the publishing process.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F16132870&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fsoftware-engineer-develop-study-programming-coding-gif-16132870&amp;image=https%3A%2F%2Fmedia.tenor.com%2FyiaAYqLlJfoAAAAF%2Fsoftware-engineer-develop.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b6f1381604a1797a996456e849621ad/href">https://medium.com/media/8b6f1381604a1797a996456e849621ad/href</a></iframe><ul><li>First, we run a <strong>pod</strong> command to check the validity of a CocoaPods Podspec file. This includes verifying the syntax, dependencies, and other metadata specified in the Podspec.</li></ul><pre>pod spec lint</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvYHgZG17yE83eWYpUChKw.png" /><figcaption>If there are no errors, it should pass validation checks and you’ll see this message in your terminal</figcaption></figure><ul><li>Next, we run a <strong>pod</strong> command that validates and verifies the integrity of an entire CocoaPods library project, including its Podspec file. It ensures that your library project adheres to CocoaPods’ guidelines and best practices, such as having the correct directory structure, including proper documentation, and following naming conventions.</li></ul><pre>pod lib lint</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtKXiTYhrDV01J_ZrzzgxA.png" /><figcaption>If there are no errors, it should pass validation checks and you’ll see this message in your terminal</figcaption></figure><ul><li>Now that we’ve passed all validation checks, we’ll register our account as a trusted user account on the CocoaPods Trunk service. To do this type the following <strong>podcommand</strong> with your updated personal details in the terminal. After the command is executed, you’ll receive a confirmation link on your registered email ID and you’ll be verified.</li></ul><pre>pod trunk register &quot;email@email.com&quot; &quot;your name&quot; --description=&quot;Device name&quot;</pre><ul><li>Next, we’ll use a <strong>pod</strong> command that will display information about the currently authenticated user on the CocoaPods Trunk service. This will help us ensure that our device and account are successfully registered with CocoaPods Trunk service or not.</li></ul><pre>pod trunk me</pre><ul><li>Lastly, we use the <strong>pod</strong> command to publish the new version of our library to Cocoapods.</li></ul><pre> pod trunk push Snacky.podspec</pre><p>After running this command, you should see something like this in your terminal. As you can see our library is successfully published in Cocoapods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TEHPasALDjB8_F-v6swUnQ.png" /></figure><p>Now other developers/organizations can use your library just by using a simple <strong>pod</strong> command.</p><pre>pod &#39;Snacky&#39;</pre><h4>Step 4: Publishing a Private Pod</h4><p>This tutorial currently does not cover creating and publishing a private pod. I’ll make a future series on that too, but in the meanwhile, if you’re someone looking to build and publish a private pod, I’ll leave some good resources for it.</p><ol><li><a href="https://guides.cocoapods.org/making/private-cocoapods.html">https://guides.cocoapods.org/making/private-cocoapods.html</a></li><li><a href="https://guides.cocoapods.org/making/specs-and-specs-repo.html">https://guides.cocoapods.org/making/specs-and-specs-repo.html</a></li><li><a href="https://medium.com/@shahabejaz/create-and-distribute-private-libraries-with-cocoapods-5b6507b57a03">https://medium.com/@shahabejaz/create-and-distribute-private-libraries-with-cocoapods-5b6507b57a03</a></li></ol><h4>Step 5: Conclusion &amp; Future Steps</h4><p>If you’ve followed the steps from both parts of this series, and now you have your library published in Cocoapods, Great work and Congratulations🎉🎊🥳.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F14385738&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fthe-office-kevin-malone-oscar-martinez-darryl-philbin-dancing-gif-14385738&amp;image=https%3A%2F%2Fmedia.tenor.com%2FFdrN9R_kgwoAAAAN%2Fthe-office-kevin-malone.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/468a8a1becd0262334394905768a583d/href">https://medium.com/media/468a8a1becd0262334394905768a583d/href</a></iframe><p>If you’re stuck in any part or encounter any issues, feel free to reach out to me and comment on your issues.</p><p>You can find the source code of this project on my GitHub. Here is the GitHub repository <a href="https://github.com/prashant564/SnackyIOS"><strong>link</strong></a>.</p><p>Thanks a lot for reading this article and follow me for upcoming articles related to app development. Please give a clap if found this article useful. Happy learning😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=368c612d8ca5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating and publishing your own iOS library in Swift(2024) | Part 1]]></title>
            <link>https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-ios-library-in-swift-2024-part-1-4dd8b211802a?source=rss-f3c53b095310------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dd8b211802a</guid>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[cocoapods]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Prashant Dixit]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 13:21:19 GMT</pubDate>
            <atom:updated>2024-04-13T13:21:19.808Z</atom:updated>
            <content:encoded><![CDATA[<p>In this comprehensive beginner’s guide, we will embark on an exciting journey into the realm of iOS development. Get ready to create your very own iOS library using Swift and learn how to publish it so it can be used by other developers/organizations. So, without further ado, let’s dive into the benefits of building a library and start building one of our own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrtgQZ0uBAFJ1xGp0cRvzQ.jpeg" /></figure><p><strong>What is an iOS Library &amp; why should I make one as a developer?</strong></p><p>In today’s fast-paced world of iOS development, it’s crucial to grasp the concept of creating your own iOS library. Why? Picture this: you’re working on an iOS app, and you want to incorporate some innovative features or functionalities. Instead of reinventing the wheel each time, you can streamline your workflow by utilizing pre-built modules known as libraries.</p><p>These libraries serve as pre-made components that seamlessly integrate into your app. By crafting your library, you expedite your development process and contribute to the broader developer community. It’s an excellent avenue to share your expertise and assist others in their app-building endeavors.</p><p>Now that we’ve outlined an iOS library and its benefits, let’s delve into the project setup and coding process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*UEfEEqN4GwotEuo2IQa7hQ.gif" /></figure><h3>Creating a custom iOS library in Swift</h3><p>The first step in creating any project/library is to ensure you have a good and appropriate project structure based on the needs of your projects. Since we’re creating an iOS library which will be later deployed on Cocoapods, we need to find a project structure that suits the platform.</p><p>Before we start building the project, let me give you a brief overview on what Cocoapods is. <a href="https://cocoapods.org/"><strong>CocoaPods</strong></a> is a handy tool for iOS and macOS developers. It makes managing external code libraries a breeze by automating tasks like downloading and integrating dependencies. With CocoaPods, developers can keep their projects organized and efficient with minimal effort.</p><h4>Step 1: Setting up our project and building the starter project</h4><p>Luckily Cocoapods provides a tool that is specifically designed to help you create a new CocoaPod library project with a structured directory layout and some boilerplate code. You can follow this <a href="https://guides.cocoapods.org/making/using-pod-lib-create.html"><strong>link</strong></a> to learn more.</p><p>The command to create a new Cocoapods library project is as follows</p><pre>pod lib create your_library_name</pre><ul><li>Open up the terminal in your desired folder, and paste the above command with your project name. I will be naming my project as ‘Snacky’ but you can use whatever name you want. It should look something like in the below screenshot.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pt7roENamThg-DloFpDIBg.png" /></figure><ul><li>Next, after running this command, you’ll see different setup options. Choose accordingly based on your project needs. Or just choose the ones that I have. We are creating an iOS library, which will be using <strong>Swift</strong>, for testing our library we would like to include a ‘demo project’ in our project, since this is a small sample project, we don’t require testing frameworks here.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIn-O2e3qEtK2ZiOl1Mwag.png" /></figure><ul><li>Once you’re done with all the questions, your project will build and the boilerplate code will be ready for you to start the project. Your terminal should show something like this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wWrl31vgYcDWonuk75-Ng.png" /></figure><ul><li>Now open your project in XCode, and you should see the following project structure. We have a main project folder <strong>Snacky</strong> and a <strong>Pods</strong> folder separately. Inside the Snacky folder, we have a <strong>Snacky.podspec</strong> file which will contain our library’s configurations, and an <strong>example project</strong> which we’ll use to test our library’s code.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*HLSBfuO3LnjdftU2MKJFIA.png" /></figure><ul><li>Next, we have the Pods folder, where there is another folder named Snacky, it is this folder inside which we will write all the business logic for our library. It currently has a swift file named ReplaceMe. We will remove that and create a <strong>new Swift file </strong>named <strong>Snacky</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*8fjTa5oTMLEXGmsBZm4d-g.png" /></figure><ul><li>One last thing to set up before we begin coding is to ensure that both the example project and our library have the same <strong>iOS minimum deployment target</strong> version. Click on the Pods project (Pods.xcodeproj), then in the <strong>Info</strong> tab, you see the field <strong>Deployment Target</strong>, change the value of that field to iOS version <strong>13.0 or later</strong> as per your need. But make sure that in the left-hand side <strong>Project</strong> section, <strong>Pods</strong> is selected. Here is the screenshot below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvOgrHc5ve4tIQw-50ll2g.png" /></figure><ul><li>We need to do the same thing in our<strong> Snacky Project</strong> (Snacky.xcodeproj). Click on the <strong>Info</strong> tab -&gt; Select <strong>Snacky</strong> project-&gt; Set <strong>Deployment Target</strong> value to iOS 13.0 or later.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3-6-u5eqkX3uwR5bu5q96A.png" /></figure><p>Now if we run the project, it should build successfully and open on a simulator/real device. It took a lot of steps to set up this project, but we have a good project structure and code that builds successfully, so now we go to the exciting part which is writing our custom library code. Pat yourself on the back if you’ve reached so far. Let’s go coding now.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F5368357&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcat-computer-typing-fast-gif-5368357&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fy2JXkY1pXkwAAAAN%2Fcat-computer.png&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0900b5ae0dfca43b89ba1f8626e37411/href">https://medium.com/media/0900b5ae0dfca43b89ba1f8626e37411/href</a></iframe><h4>Step 2: Adding code inside our library</h4><ul><li>Open the <strong>Snacky.swift</strong> file we created above in Pods-&gt;Development Pods -&gt; Snacky folder. We will create a custom iOS alert function that accepts parameters such as <strong>title, message, alert style</strong>, and <strong>color</strong>. This function will display a customized UIAlert to the user. By using this function, we can avoid repeatedly writing the same code to display alerts. We pass the parameters as values while we’re initializing our alertController and returning the modified alertContoller for a user to display on their screen.</li></ul><pre>import Foundation<br><br>public func createAlert(title: String, message: String, alertStyle: UIAlertController.Style?, color: UIColor?) -&gt; UIAlertController {<br>    let alertController = UIAlertController(title: title, message: message, preferredStyle: alertStyle ?? .alert)<br>    alertController.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = color<br>    <br>    return alertController<br>}</pre><p>Congratulations, pat yourself on the back. You just created your first library, well done!! Now that our library code is ready and before we deploy it, we need to test our library locally to ensure our library runs perfectly.</p><blockquote>Protip: Make it a habit to test each new version of your library when it is included in a sample project so that you can see how the changes affect the app and how simple it will be for developers to use your library. This is a no-brainer, but it will help you avoid making mistakes later on.</blockquote><h4>Step 3: Testing our library locally</h4><ul><li>Next, we go to our <strong>ViewController.swift</strong> file in our Example project, the path for which is Snacky -&gt; Example for Snacky -&gt; ViewController.swift.In this file, we’ll build a button, which when pressed will call our library’s <strong>createAlert </strong>function and display an alert. First, we import our library to this file to access Snacky’s functions.</li></ul><pre>import Snacky</pre><p>Next, we write code to programmatically create a button and implement its onPressed function which will call the <strong>Snacky.createAlert(…), </strong>and then present the returned alert to the user on the current screen.</p><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        // Do any additional setup after loading the view, typically from a nib.<br>        let button = UIButton(type: .system)<br>        button.setTitle(&quot;Display Alert&quot;, for: .normal)<br>        button.setTitleColor(.white, for: .normal)<br>        button.frame = CGRect(x: 100, y: 400, width: 200, height: 50)<br>        button.backgroundColor = .blue<br>        button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)<br>        view.addSubview(button)<br>    }</pre><pre>    @objc func buttonTapped() {<br>        let alertController = Snacky.createAlert(title: &quot;Hello&quot;, <br>                                                 message: &quot;Publishing library in iOS is fun!!&quot;,<br>                                                 alertStyle: .alert,<br>                                                 color: .gray)<br>        <br>        present(alertController, animated: true)<br>    }</pre><p>Now you can see how many customizations we can make to our Alert thanks to this function, you can play around with different configurations and properties of UIAlertController but that is beyond the scope of this article. Here is the full code for <strong>ViewController.swift </strong>file</p><pre>import UIKit<br>import Snacky<br><br>class ViewController: UIViewController {<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        // Do any additional setup after loading the view, typically from a nib.<br>        let button = UIButton(type: .system)<br>        button.setTitle(&quot;Display Alert&quot;, for: .normal)<br>        button.setTitleColor(.white, for: .normal)<br>        button.frame = CGRect(x: 100, y: 400, width: 200, height: 50)<br>        button.backgroundColor = .blue<br>        button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)<br>        view.addSubview(button)<br>    }<br>    <br>    @objc func buttonTapped() {<br>        let alertController = Snacky.createAlert(title: &quot;Hello&quot;, <br>                                                 message: &quot;Publishing library in iOS is fun!!&quot;,<br>                                                 alertStyle: .alert,<br>                                                 color: .gray)<br>        <br>        present(alertController, animated: true)<br>    }<br><br>    override func didReceiveMemoryWarning() {<br>        super.didReceiveMemoryWarning()<br>        // Dispose of any resources that can be recreated.<br>    }<br><br>}</pre><h4>Step 5: Build and Test our sample app</h4><p>Let’s build our sample app now and test whether our library is working. As you can see on clicking the button we see a UIAlert on our screen with all the custom values that we passed in our <strong>createAlert </strong>function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*0Z-6fVGVAxcUiBa2YfKz1Q.gif" /></figure><h4>Step 6: Conclusion &amp; Future Steps</h4><p>Wohooooo Enjoy🎉🎊🥳🥳.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F16435335956387921912&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcool-fun-white-cat-dance-cool-and-fun-times-gif-16435335956387921912&amp;image=https%3A%2F%2Fmedia.tenor.com%2F5BYK-WS0__gAAAAN%2Fcool-fun.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef936d798093b87798974b6cece09d43/href">https://medium.com/media/ef936d798093b87798974b6cece09d43/href</a></iframe><p>In this tutorial, we learned how to create a custom library add it to your local project and test it. In the next part of this series, we will be working on publishing our iOS library to Cocoapods and SPM.</p><p>You can find the source code of this project on my GitHub. Here is the GitHub repository <a href="https://github.com/prashant564/SnackyIOS"><strong>link</strong></a>.</p><p>Thanks a lot for reading this article and follow me for upcoming articles related to app development. Please give a clap if found this article useful. Happy learning😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dd8b211802a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating and publishing your own Android library in Kotlin (2023) | Part -1]]></title>
            <link>https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-android-library-in-kotlin-2023-part-1-3e542dad4ca0?source=rss-f3c53b095310------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e542dad4ca0</guid>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-libraries]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Prashant Dixit]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 07:53:10 GMT</pubDate>
            <atom:updated>2025-11-30T15:58:48.839Z</atom:updated>
            <content:encoded><![CDATA[<p>In this comprehensive beginner’s guide, we will embark on an exciting journey into the realm of Android development. Get ready to create your very own Android library using Kotlin and learn how to publish it so it can be used by other developers/organizations. So, without further ado, let’s dive into the benefits of building a library and start building one of our own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXjYEbyqmFWAuPaqDdR-Mg.jpeg" /></figure><h4><strong>What is an Android Library &amp; why should I make one as a developer?</strong></h4><p>In today’s fast-paced world of Android development, it’s important to learn how to create your own Android library. Why? Well, imagine you’re building a mobile app, and you want to add some cool features or functionalities. Instead of starting from scratch every time, you can save time and effort by using pre-built modules called libraries.</p><p>These libraries are like ready-made building blocks that you can easily plug into your app. By creating your own library, you not only make your development process faster but also contribute to the larger community of developers. It’s a great way to share your knowledge and help others in their app-building journey.</p><p>With our what and why answered, let’s start coding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*NHx95XIxeb244OvYtpjRDg.gif" /></figure><h3>Creating a custom Android library in Kotlin</h3><h4><strong>Step 1: Setting up our sample project</strong></h4><p>Open Android Studio and start a new project with Empty Views Activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kxd74aWWk02_knokhwl1aQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVGzxtQeAMHw-LwG9mw6oA.png" /><figcaption>Click on Finish and a new project will be created</figcaption></figure><h4><strong>Step 2: Setting up our Library codebase</strong></h4><p>Once the project is loaded, to create a new library module, click <strong>File -&gt; New -&gt; New Module…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TM1a-zRCyneFlheunYNf5Q.png" /></figure><p>This will open a <strong>“Create New Module”</strong> window<strong>. </strong>Here you can see many different templates for creating new modules. In our case, we need to select <strong>Android Library</strong> from the list of templates and give a title to our library. Once you’ve done that, Click on <strong>Finish</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CPbyVtczBs4GdBGBXrLcuA.png" /></figure><p>If you have followed the steps mentioned above correctly, you will discover a brand new project folder having the same name as you provided while creating your new library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*TgjK1fjYH2Vzu-nfY8Sg3g.png" /></figure><h4><strong>Step 3:</strong> Adding code inside our library</h4><p>Let&#39;s add code to our library. In this tutorial, we will be using Android’s <a href="https://developer.android.com/reference/com/google/android/material/snackbar/Snackbar"><strong>Snackbar</strong></a> component which shows brief messages on the screen. It provides a non-intrusive way to show informative or actionable messages to the user.</p><p>In our library, we’ll create a customizable Snackbar which can be integrated into other applications without the need to write long boilerplate code and add customizations manually.</p><ul><li>For this tutorial, we will import Snackbar from Android’s Material Design library. Add the following dependency, in your Library’s Module level build.gradle file.</li></ul><pre>dependencies {<br>  //rest of code<br>  ...<br>  implementation &#39;com.google.android.material:material:1.9.0&#39;<br>}</pre><ul><li>Inside the Java folder of your library, add a new Kotlin Object file. It should look something like this</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*WyusNfP2epvuufQUVvscQw.png" /></figure><ul><li>Next, add the following code to the file we created in the last step.</li></ul><pre>import android.view.Gravity<br>import android.view.View<br>import android.widget.FrameLayout<br>import android.widget.TextView<br>import androidx.core.content.ContextCompat<br>import com.google.android.material.snackbar.Snackbar<br><br><br>object Snacky {<br>    fun showSnackbar(view: View, message: String) {<br>        val snackbar = Snackbar.make(view, message, Snackbar.LENGTH_LONG)<br>        val snackbarView = snackbar.view<br><br>        // Set text color<br>        val textView = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text) as? TextView<br>        textView?.setTextColor(ContextCompat.getColor(view.context, android.R.color.white))<br><br>        // Set position<br>        val params = snackbarView.layoutParams as? FrameLayout.LayoutParams<br>        params?.gravity = Gravity.TOP<br>        snackbarView.layoutParams = params<br><br>        snackbar.show()<br>    }<br>}</pre><p>In the above code, the <strong>showSnackbar</strong> function takes two parameters, <strong>view, </strong>and<strong> message</strong>. It creates a Snackbar with the given message and time duration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*00Q7ybXWnsSLSjGf0Ktwag.gif" /></figure><p>Congratulations, pat yourself on the back. You just created your first library, well done!! Now that our library code is ready and before we deploy it, we need to test our library locally to ensure our library runs perfectly.</p><blockquote>Protip: Make it a habit to test each new version of your library when it is included in a sample project so that you can see how the changes affect the app and how simple it will be for developers to use your library. This is a no-brainer, but it will help you avoid making mistakes later on.</blockquote><p>In the next step, we’ll do just that.</p><h4>Step 4: Testing our library locally</h4><p>At the beginning of the tutorial, we created a new Android Studio project. Now, we will utilize this project to test our library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*xyApgfcVLh3Wfm7Pm482FA.png" /></figure><p>In the above image you can see we have two folders, first is <strong>app </strong>folder that contains the<strong> </strong>project files for the CustomSnackbar project, and second, we have our library named <strong>Snacky</strong>.</p><ul><li>Add Snacky library dependency to the project.</li></ul><p>Add the following code to the dependency array in <strong>(Module: app) </strong>build.gradle file</p><pre>dependencies {<br>  //rest of code<br>  ...<br>  implementation project(&#39;:Snacky&#39;)<br>}</pre><p>Since our library is not hosted on any repository hosting services yet, we will add it as a Project level dependency for local testing. By doing this, our CustomSnackbar project now has access to the library’s code.</p><ul><li>In the <strong>MainActivity.kt</strong> file of your app, import the <strong>Snacky</strong> object from our snacky library.</li></ul><pre>...<br>import com.prashd.snacky.Snacky<br><br>class MainActivity : AppCompatActivity() {<br>...<br>}</pre><ul><li>Next, go to the <strong>activity_main.xml</strong> file, we’ll add a button here, which when clicked will show the Snackbar.</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:context=&quot;.MainActivity&quot;<br>    android:id=&quot;@+id/rootView&quot;<br>    &gt;<br><br>    &lt;Button<br>        android:id=&quot;@+id/btn_snackbar&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:text=&quot;Show  Snackbar&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;<br><br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><ul><li>Now, let’s add functionality to the <strong>MainActivity.kt</strong> file. We’ll handle the button click event and pass the root view (identified by its XML layout ID) to the <strong>showSnackbar</strong> function. This will ensure that the Snackbar is displayed on the appropriate part of the screen. Here’s the updated code snippet:</li></ul><pre>import androidx.appcompat.app.AppCompatActivity<br>import android.os.Bundle<br>import android.view.View<br>import android.widget.Button<br>import com.prashd.snacky.Snacky<br><br>class MainActivity : AppCompatActivity() {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        val rootView: View = findViewById(R.id.rootView)<br><br>        val button = findViewById&lt;Button&gt;(R.id.btn_snackbar)<br><br>        button.setOnClickListener {<br>            Snacky.showSnackbar(rootView, &quot;This is a test message!!&quot;)<br>        }<br><br>    }<br>}</pre><h4><strong>Step 5: Build and Test our sample app</strong></h4><p>Now run the sample app and test the code. If you’ve followed the above steps, you should see the Snackbar appear when the button is clicked. Here is a demo response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*i8hk2vd6dKYQaIZ4cF9sQQ.gif" /></figure><h4><strong>Step 6: Conclusion &amp; Future Steps</strong></h4><p>Enjoy!! 🥳🎊🎉🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*YCpO8iT4rbORKbSJ56w1AA.gif" /></figure><p>In this tutorial, we learned how to create a custom library and add it to your local project and test it. In the next part of this series, we will be working on publishing our Android library to Maven.</p><p>You can find the source code of this project on my GitHub. Here is the GitHub repository <a href="https://github.com/prashant564/CustomSnackbar"><strong>link</strong></a>.</p><p>The second part of this series is now available and we go into detail on how to publish our Android library to Maven Central using the <strong>Upload</strong> method. Here is the <a href="https://medium.com/@prashantdixit_87612/creating-and-publishing-your-own-android-library-in-kotlin-maven-central-upload-2025-part-2-5c85818d20fd">link</a> to Part 2.</p><p>Thanks a lot for reading this article and follow me for upcoming articles related to app development. Please give a clap if found this article useful. Happy learning😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e542dad4ca0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Firebase and using Realtime Database]]></title>
            <link>https://medium.com/@prashantdixit_87612/getting-started-with-firebase-and-using-realtime-database-a319494aa748?source=rss-f3c53b095310------2</link>
            <guid isPermaLink="false">https://medium.com/p/a319494aa748</guid>
            <category><![CDATA[realtime-database]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Prashant Dixit]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 11:39:15 GMT</pubDate>
            <atom:updated>2019-10-28T15:11:31.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with Firebase and Realtime Database</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G23y70FA_6FUs1kcoJ4pIA.png" /></figure><p>Firebase is a Backend-as-a-Service — BaaS- which allows developers to build web and mobile applications without a server-side programming language. It is a NoSQL type database that makes use of sockets, which allows the client to receive information live — without having to make GET requests to the server.</p><p>There are three main services to Firebase:</p><ul><li>Realtime database</li><li>Authentication</li><li>Static Hosting</li></ul><p>This article gets you started with how to integrate your app with Firebase and how to store and retrieve data from Firebase Real-Time Database. Follow the following steps to get started.</p><h4>1. In your Android Studio project, go to Tools and select Firebase option</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FErmq9IFqKl9Cz20pWMI8w.png" /></figure><p><strong>2. Click on the Realtime Database option.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlFuYea1Wk97DEbQlXcm2Q.png" /></figure><p><strong>3. Click on connect to Firebase and the following popup comes, make changes(if you need to) and click on the “connect to Firebase” button.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1faUzHOh6GoJfjq4uedPA.png" /></figure><p><strong>4. Then click on Add the Realtime Database to your app option and press “Accept Changes” to add the necessary dependencies.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvxvffTNjUiYaB7IQZIEVA.png" /></figure><p>If the above steps are completed successfully, you will get a message like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y5xpiWPVMQHW5Vw4T5NSdQ.png" /></figure><p>Now that we have integrated our app with Firebase, let&#39;s start working on the realtime database.</p><p>Go to <a href="https://console.firebase.google.com/">https://console.firebase.google.com</a>, and open your project. There a dashboard will appear and you need to click on the Database menu. Then go to the firebase realtime database. And inside the rules, you need to make changes in order to store data from the app and click on Publish after making the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-9jnNqTqRQj-v05k3wbIg.png" /></figure><p>Now create a model class inside your Android Studio project, which will store our item data and business logic. Create a package named <strong>model </strong>and inside it create a Kotlin class <strong>Coin.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_N2MTlMwb1E22N0ES8q_g.png" /></figure><p>Following is the code for Coin.kt, copy and paste it into your project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d54f2934a1964f4610f819bcc75f7dd6/href">https://medium.com/media/d54f2934a1964f4610f819bcc75f7dd6/href</a></iframe><p>Now finally paste this code to your MainActivity.kt class and run the app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5197e30a811384c63d7f89cf4bb6d5e/href">https://medium.com/media/d5197e30a811384c63d7f89cf4bb6d5e/href</a></iframe><p>Now if you have followed the steps correctly, the “sample_data” table would’ve been created with one row inside it. It would look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1reenJ6CrHtCYgktOC1k0g.png" /></figure><p>Hooray!!! Pat yourself on the back as with these simple steps you have now learned how to integrate your app with Firebase and how to use Realtime Database to store your item data.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F13226780&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fwill-smith-clap-yay-happy-hooray-gif-13226780&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fae103819cb05a0cf7497900b77b87d80%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/94009953219c03776af9b5f63fac5ef9/href">https://medium.com/media/94009953219c03776af9b5f63fac5ef9/href</a></iframe><p><strong><em>Thanks for reading out the article. Let me know if I have missed out on something interesting so that it can be added. Be sure to clap/recommend as much as you can and also share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a319494aa748" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kotlin]Adding an Image Slider below a transparent toolbar using ViewPager and FrameLayout]]></title>
            <link>https://medium.com/@prashantdixit_87612/kotlin-adding-an-image-slider-below-a-transparent-toolbar-using-viewpager-and-framelayout-3847da36b832?source=rss-f3c53b095310------2</link>
            <guid isPermaLink="false">https://medium.com/p/3847da36b832</guid>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[viewpager]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[pageradapter]]></category>
            <dc:creator><![CDATA[Prashant Dixit]]></dc:creator>
            <pubDate>Sun, 18 Aug 2019 10:36:37 GMT</pubDate>
            <atom:updated>2019-08-20T23:54:48.904Z</atom:updated>
            <content:encoded><![CDATA[<p><em>viewPager for Image Slider, FrameLayout for transparent toolbar</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*qehczVQDiXLQI9UUUcGH1w.png" /></figure><p>This article is a beginners guide to implementing an Image Slider in Android below a transparent toolbar using Kotlin. Though the image slider can be implemented by both recyclerView and viewPager, we will be using viewPager in this tutorial as it is efficient and easy to understand as compared to recyclerView. We will use FrameLayout for creating a transparent toolbar and for placing the viewPager below the toolbar.</p><p>Android ViewPager introduced in API version 21 is a layout manager that allows the user to flip left and right through pages of data. In this article, we use android’s own viewPager library, as it is designed to show one item at a time since the visible item takes up the entire screen and swiping is limited to one item, it works just perfectly as an image slider.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D89maN3dq1M1ZWrvT7apyQ.png" /></figure><h3><strong>Step 1: Adding a transparent toolbar and viewPager widget inside FrameLayout</strong></h3><p>Android Toolbar was added in API 21 and is a successor of ActionBar. There are a lot of ways of implementing a transparent toolbar in Android but the simplest and easy to use method is by using Frame Layout as it comes in handy when you want to overlay a View over another View.</p><p>Although FrameLayout should be used for holding a single child view, we use it to overlay an image slider below a transparent toolbar, by adding viewPager and toolbar widget as children to the FrameLayout and controlling their position within the layout by assigning gravity using the <a href="https://developer.android.com/reference/android/widget/FrameLayout.LayoutParams.html#attr_android:layout_gravity">android:layout_gravity</a>attribute. Inside the toolbar, we set this attribute to “top”.</p><p>So below is the code to be added in the <em>app_bar_main.xml</em> of the navigation drawer activity of your project. This should run without any errors.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout<br>        xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>        xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>        xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        tools:context=&quot;.MainActivity&quot;&gt;<br><br>    &lt;com.google.android.material.appbar.AppBarLayout<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:theme=&quot;@style/AppTheme.AppBarOverlay&quot;&gt;<br><br>        &lt;FrameLayout<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;match_parent&quot;&gt;<br>            <br>            &lt;androidx.viewpager.widget.ViewPager             android:layout_width=&quot;match_parent&quot;<br>                                                 android:layout_height=&quot;200dp&quot;<br><br>                                                 android:id=&quot;@+id/viewpager&quot;&gt;<br>            &lt;/androidx.viewpager.widget.ViewPager&gt;<br><br>            <br>            &lt;androidx.appcompat.widget.Toolbar<br>                    android:id=&quot;@+id/toolbar&quot;<br>                    android:layout_width=&quot;match_parent&quot;<br>                    android:layout_height=&quot;?attr/actionBarSize&quot;<br>                    android:layout_gravity=&quot;top&quot;<br>                    android:background=&quot;@android:color/transparent&quot;<br>                    app:popupTheme=&quot;@style/AppTheme.PopupOverlay&quot;/&gt;<br><br>        &lt;/FrameLayout&gt;<br><br>    &lt;/com.google.android.material.appbar.AppBarLayout&gt;<br><br>    &lt;include layout=&quot;@layout/content_main&quot;/&gt;<br><br>    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton<br>            android:id=&quot;@+id/fab&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_gravity=&quot;bottom|end&quot;<br>            android:layout_margin=&quot;@dimen/fab_margin&quot;<br>            app:srcCompat=&quot;@android:drawable/ic_dialog_email&quot;/&gt;<br><br>&lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;</pre><h3>Step 2: Adding images</h3><p>Add images to show in the slider, by copy and pasting the images in your system to the drawable folder under res section of your project.</p><h3><strong>Step 3: Creating a single slide layout</strong></h3><p>Create a new layout resource file named <em>image_slider_item.xml</em> to represent the UI of each page in the viewPager.</p><p>Add the following source code given below to this file.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>                                                   xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>                                                   xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>                                                   android:orientation=&quot;vertical&quot;<br>                                                   android:layout_width=&quot;match_parent&quot;<br>                                                   android:layout_height=&quot;match_parent&quot;&gt;<br><br>    &lt;ImageView<br>            android:layout_width=&quot;0dp&quot;<br>            android:layout_height=&quot;0dp&quot; tools:srcCompat=&quot;@tools:sample/backgrounds/scenic&quot;<br>            android:id=&quot;@+id/imageView_slide&quot; app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>            app:layout_constraintEnd_toEndOf=&quot;parent&quot; app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>            app:layout_constraintBottom_toBottomOf=&quot;parent&quot; android:scaleType=&quot;fitXY&quot;/&gt;<br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><h3><strong>Step 4: Creating a custom PagerAdatper class</strong></h3><p>Introduced in version <a href="https://developer.android.com/topic/libraries/support-library/revisions.html">22.1.0</a> of Android, PagerAdapter is a base class used to fill the data inside of a viewPager. This class inherits from the android default PagerAdapter class and its each call results to a change in the viewPager’s content.</p><p>Under the java folder, right-click on your project directory, click on new, select Kotlin file/class and name this file as <em>ImageSliderAdapter.kt</em></p><p>Copy the following code and add it to this newly created file.</p><pre>package com.example.myapplication<br><br>import android.content.Context<br>import android.view.LayoutInflater<br>import android.view.View<br>import android.view.ViewGroup<br>import androidx.viewpager.widget.PagerAdapter<br>import androidx.viewpager.widget.ViewPager<br>import kotlinx.android.synthetic.main.image_slider_item.view.*<br><br>class ImageSliderAdapter(private val context: Context) : PagerAdapter() {<br><br><br>    private var inflater: LayoutInflater? = null<br>    private val images = <em>arrayOf</em>(R.drawable.<em>anton</em>, R.drawable.<em>frankjpg</em>, R.drawable.<em>redcharlie</em>, R.drawable.<em>westboundary</em>)<br><br>    override fun isViewFromObject(view: View, `object`: Any): Boolean {<br><br>        return view === `object`<br>    }<br><br>    override fun getCount(): Int {<br><br>        return images.size<br>    }<br><br>    override fun instantiateItem(container: ViewGroup, position: Int): Any {<br><br>        inflater = context.getSystemService(Context.<em>LAYOUT_INFLATER_SERVICE</em>) as LayoutInflater<br>        val view = inflater!!.inflate(R.layout.<em>image_slider_item</em>, null)<br>        view.imageView_slide.setImageResource(images[position])<br><br>        val vp = container as ViewPager<br>        vp.addView(view, 0)<br>        return view<br>    }<br><br>    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {<br><br>        val vp = container as ViewPager<br>        val view = `object` as View<br>        vp.removeView(view)<br>    }<br><br>}</pre><h3><strong>Step 5: Update your Main Activity.kt class</strong></h3><p>Add an <em>imageSliderImplementation</em> function in the MainActivity.kt class to implement the viewPager to slide images. Inside this function, we obtain instances of viewPager and ImageSliderAdapter. viewPager calls the adapter method and the instance of the ImageSliderAdapter is passed as a parameter.</p><p>Replace the existing code in your main activity class with this code.</p><pre>package com.example.myapplication<br><br>import android.os.Bundle<br>import android.view.Menu<br>import android.view.MenuItem<br>import androidx.appcompat.app.ActionBarDrawerToggle<br>import androidx.appcompat.app.AppCompatActivity<br>import androidx.appcompat.widget.Toolbar<br>import androidx.core.view.GravityCompat<br>import androidx.drawerlayout.widget.DrawerLayout<br>import com.google.android.material.floatingactionbutton.FloatingActionButton<br>import com.google.android.material.navigation.NavigationView<br>import com.google.android.material.snackbar.Snackbar<br>import kotlinx.android.synthetic.main.app_bar_main.*<br><br>class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {<br><br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br>        val toolbar: Toolbar = findViewById(R.id.<em>toolbar</em>)<br>        setSupportActionBar(toolbar)<br><br>        val fab: FloatingActionButton = findViewById(R.id.<em>fab</em>)<br>        fab.setOnClickListener <strong>{ </strong>view <strong>-&gt;<br>            </strong>Snackbar.make(view, &quot;Replace with your own action&quot;, Snackbar.<em>LENGTH_LONG</em>)<br>                .setAction(&quot;Action&quot;, null).show()<br>        <strong>}<br>        </strong>val drawerLayout: DrawerLayout = findViewById(R.id.<em>drawer_layout</em>)<br>        val navView: NavigationView = findViewById(R.id.<em>nav_view</em>)<br>        val toggle = ActionBarDrawerToggle(<br>            this, drawerLayout, toolbar, R.string.<em>navigation_drawer_open</em>, R.string.<em>navigation_drawer_close<br>        </em>)<br>        drawerLayout.addDrawerListener(toggle)<br>        toggle.syncState()<br><br>        navView.setNavigationItemSelectedListener(this)<br><br>        imageSliderImplementation()<br><br><br>    }<br><br>    private fun imageSliderImplementation() {<br><br>        val adapter = ImageSliderAdapter(this)<br>        viewpager.<em>adapter </em>= adapter<br><br><br>    }<br><br>    override fun onBackPressed() {<br>        val drawerLayout: DrawerLayout = findViewById(R.id.<em>drawer_layout</em>)<br>        if (drawerLayout.isDrawerOpen(GravityCompat.<em>START</em>)) {<br>            drawerLayout.closeDrawer(GravityCompat.<em>START</em>)<br>        } else {<br>            super.onBackPressed()<br>        }<br>    }<br><br>    override fun onCreateOptionsMenu(menu: Menu): Boolean {<br>        // Inflate the menu; this adds items to the action bar if it is present.<br>        <em>menuInflater</em>.inflate(R.menu.<em>main</em>, menu)<br>        return true<br>    }<br><br>    override fun onOptionsItemSelected(item: MenuItem): Boolean {<br>        // Handle action bar item clicks here. The action bar will<br>        // automatically handle clicks on the Home/Up button, so long<br>        // as you specify a parent activity in AndroidManifest.xml.<br>        return when (item.<em>itemId</em>) {<br>            R.id.<em>action_settings </em>-&gt; true<br>            else -&gt; super.onOptionsItemSelected(item)<br>        }<br>    }<br><br>    override fun onNavigationItemSelected(item: MenuItem): Boolean {<br>        // Handle navigation view item clicks here.<br>        when (item.<em>itemId</em>) {<br>            R.id.<em>nav_home </em>-&gt; {<br>                // Handle the camera action<br>            }<br>            R.id.<em>nav_gallery </em>-&gt; {<br><br>            }<br>            R.id.<em>nav_slideshow </em>-&gt; {<br><br>            }<br>            R.id.<em>nav_tools </em>-&gt; {<br><br>            }<br>            R.id.<em>nav_share </em>-&gt; {<br><br>            }<br>            R.id.<em>nav_send </em>-&gt; {<br><br>            }<br>        }<br>        val drawerLayout: DrawerLayout = findViewById(R.id.<em>drawer_layout</em>)<br>        drawerLayout.closeDrawer(GravityCompat.<em>START</em>)<br>        return true<br>    }<br>}</pre><p>After following these five steps, run your code and you should get a UI like in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*evMIdeGcBZ6AGZC6gWK6Pw.png" /></figure><p>Congratulations! Pat yourself on the back as with only this much of code you have learned how to implement an image slider using viewPager and also how to use FrameLayout for making toolbar transparent as well as for adding views below the toolbar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*KowWujusMfDjlkjeeOFEBg.gif" /></figure><p>You can find the source code of this project on my Github repository. Here is the link of that repository:</p><p><a href="https://github.com/prashant564/ImageSliderApp">https://github.com/prashant564/ImageSliderApp</a></p><p>Thanks a lot for reading this article and watch this space closely for upcoming articles related to android app development using Kotlin.Please do give a clap if you found this article useful. Happy coding :D.</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYxBP_WV7LI6zc-zdUkNqQ.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3847da36b832" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>