# Android Kmp Shared

> Use when building Kotlin Multiplatform (KMP) shared modules, integrating with iOS, or sharing business logic across platforms.

- **Type:** Skill
- **Install:** `agentstack add skill-prasad-vennam-awesome-android-ai-agent-skills-android-kmp-shared`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [prasad-vennam](https://agentstack.voostack.com/s/prasad-vennam)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [prasad-vennam](https://github.com/prasad-vennam)
- **Source:** https://github.com/prasad-vennam/Awesome-Android-AI-Agent-Skills/tree/main/skills/android-kmp-shared

## Install

```sh
agentstack add skill-prasad-vennam-awesome-android-ai-agent-skills-android-kmp-shared
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Android Kotlin Multiplatform (KMP) 🌍🤝

Professional patterns for sharing code between Android and iOS using the next-generation Kotlin Multiplatform technology.

## ⚡ When to Use
- **Shared Business Logic**: Centralizing ViewModels, Use Cases, and Domain Models.
- **Data Layer Sharing**: Using Ktor (Network) and SQLDelight (Database) across platforms.
- **Modularization**: Creating a cross-platform library module.
- **Migration**: Moving from 100% native to shared logic.
- **Validation**: Building one logic for both apps (e.g., Auth, Calculations).

## 🏗️ The Multiplatform Architecture

- **`commonMain`**: The heart of the app. Pure Kotlin code shared by all platforms.
- **`androidMain`**: Platform-specific implementation for Android.
- **`iosMain`**: Platform-specific implementation for iOS (via Kotlin/Native).

## 🛠️ Essential Shared Tools

### 1. Ktor (Networking)
- **Benefit**: Async, multiplatform HTTP client.
- Use `ContentNegotiation` and `Serialization` for shared DTOs.

### 2. SQLDelight (Local Persistence)
- **Benefit**: Type-safe SQL queries that generate Kotlin code.
- Shared schema, platform-specific drivers (SQLite for Android, Native for iOS).

### 3. Koin (Dependency Injection)
- **Benefit**: Simple and lightweight DI that works across `commonMain`.

### 4. kotlinx-datetime
- Use for consistent date/time logic without platform-specific issues (java.time vs NSDate).

## 🚀 The `expect` / `actual` Pattern

- Use for platform-specific APIs when no shared library exists.
- **Rule**: Avoid `expect`/`actual` if a shared library is available.
- **Bad**: `expect fun getPlatformName(): String`
- **Good**: Use **interfaces** and **DI** to provide platform-specific implementations.

## 🏁 Shared Logic Workflow

- [ ] **ViewModel Sharing**: Use `multiplatform-viewmodel` library for consistent lifecycle mapping.
- [ ] **State Management**: Use `StateFlow` in `commonMain` to expose UI state.
- [ ] **iOS Interoperability**: Be aware of Swift/Kotlin memory management and `@ObjCName` for clean iOS APIs.

## 📦 Gradle Configuration

```kotlin
kotlin {
    androidTarget()
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    sourceSets {
        commonMain.dependencies {
            implementation("io.ktor:ktor-client-core:2.3.0")
        }
    }
}
```

## 🧪 Testing with KMP

- Tests in `commonTest` run on both Android and iOS targets.
- Use `kotlin.test` for standard assertions (`assertTrue`, `assertEquals`).
- Mocking: Use libraries like **Mockative** or **KMock** for multiplatform mocking.

## 🔗 Related Resources
- [KMP Official Guide](https://kotlinlang.org/docs/multiplatform.html)
- [KMP Samples (By JetBrains)](https://github.com/Kotlin/kmp-samples)
- [Clean Architecture Skill](../android-clean-architecture/SKILL.md)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [prasad-vennam](https://github.com/prasad-vennam)
- **Source:** [prasad-vennam/Awesome-Android-AI-Agent-Skills](https://github.com/prasad-vennam/Awesome-Android-AI-Agent-Skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-prasad-vennam-awesome-android-ai-agent-skills-android-kmp-shared
- Seller: https://agentstack.voostack.com/s/prasad-vennam
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
