Skip to main content

Fixing the Razorpay-Pod Issue in Kotlin Multiplatform Mobile (KMM) for iOS

Fixing Razorpay CocoaPod Integration in KMM for iOS

Fixing Razorpay CocoaPod Integration in KMM for iOS

Kotlin Multiplatform Mobile (KMM) enables developers to share code between Android and iOS. However, integrating certain CocoaPods, such as **razorpay-pod**, can be challenging due to naming conventions. This guide provides a step-by-step solution to resolve these issues, ensuring a smooth integration of Razorpay's SDK into your KMM iOS application.

Understanding the Issue

When integrating **razorpay-pod** into a KMM project, developers may encounter errors related to unresolved modules. This often stems from the hyphen in the pod's name, which can cause KMM to misinterpret the module structure, leading to import issues.

Solution: Explicitly Defining the moduleName

Step 1: Update Your Gradle Configuration

In your shared module's build.gradle.kts file, add the following code to explicitly define the module name:

kotlin {
    ios {
        binaries.framework {
            baseName = "shared"
        }
    }
    cocoapods {
        summary = "KMM shared module for iOS"
        homepage = "https://www.kmmprogrammingnest.com"
        ios.deploymentTarget = "14.0"
        podfile = project.file("../iosApp/Podfile")
        
        pod("razorpay-pod") {
            version = "1.4.0"
            moduleName = "Razorpay"
            extraOpts += listOf(
                "-framework", "Security",
                "-framework", "SystemConfiguration",
                "-framework", "WebKit"
            )
        }
    }
}

Step 2: Synchronize and Refresh Your Project

  • **Sync the Gradle files:** In Android Studio, navigate to *File > Sync Project with Gradle Files*.
  • **Invalidate Caches (if necessary):** If issues persist, go to *File > Invalidate Caches & Restart*.

Step 3: Configure Your iOS Podfile

platform :ios, '14.0'

target 'iosApp' do
    use_frameworks!
    pod 'razorpay-pod', '1.4.0'
end

Step 4: Build and Test in Xcode

Import the Razorpay module in your Swift code:

import Razorpay

Test the integration by using the following code in your Swift class:

import UIKit
import Razorpay

class ViewController: UIViewController, RazorpayPaymentCompletionProtocol {
    var razorpay: RazorpayCheckout!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.razorpay = RazorpayCheckout.initWithKey("YOUR_API_KEY", andDelegate: self)
    }
    func onPaymentSuccess(_ payment_id: String) {
        print("Payment Successful: \(payment_id)")
    }
    func onPaymentError(_ code: Int32, description str: String) {
        print("Payment Failed: \(str)")
    }
}

Why This Solution Works

The core issue is that KMM does not automatically resolve CocoaPods with hyphenated names. By explicitly specifying the **moduleName** as **`Razorpay`**, KMM correctly maps the dependency, allowing imports to work without issues.

Following these steps will ensure seamless integration of the Razorpay SDK into your KMM project, avoiding common pitfalls and improving development efficiency.

Comments

Popular posts from this blog

How to Load Images in Kotlin Multiplatform (KMM) Using Coil

How to Load Images in Kotlin Multiplatform (KMM) Using Coil How to Load Images in Kotlin Multiplatform (KMM) Using Coil Feature Description Library Used Coil (Image Loading Library) Platforms Supported Android, iOS, Web, Desktop (via KMM) Key Benefits Fast, lightweight, easy integration Implementation Kotlin Multiplatform with Jetpack Compose & SwiftUI Use Cases Displaying remote/local images, caching, placeholders Introduction to KMM and Coil Kotlin Multiplatform (KMM) allows developers to build cross-platform apps for Android, iOS, Web, and Desktop with a single codebase. One challenge in KMM is image loading since different platforms handle images differently. The Coil image loading library , originally built for Android, now supports Kotlin Multiplatform and integrates smoothly with Jetpack Compose, offering a robust solution. Why Use Coil ...

Build Once, Run Anywhere: A Simple Weather App using Kotlin Multiplatform (KMM/KMP/CMP)

Simple Weather App using Kotlin Multiplatform (KMM/KMP) Simple Weather App using Kotlin Multiplatform (KMM/KMP) 🚀 In today’s cross-platform app development world, Kotlin Multiplatform (now popularly known as KMP or KMM ) is a game-changer. It allows us to share business logic across Android and iOS without compromising the native feel and performance of the UI. As a passionate mobile developer, I recently built a Simple Weather Application using KMP (Kotlin Multiplatform Project) . This app is a real-world example of how you can target both Android and iOS platforms with a single codebase using: 💻 Jetpack Compose for Android UI 🍎 SwiftUI for iOS UI ⚙️ Shared business logic in Kotlin 🔗 GitHub Project Link 🌟 Why Kotlin Multiplatform (KMP)? Unlike Flutter or React Native, KMP doesn't replace the native UI — instead, it empowers developers to write platform-s...