Docs

Getting started

Set up the two projects and use a Kotlin function and a Compose component from an existing React Native app.

On this page

Start with a React Native app and a Kotlin Multiplatform module. The installation demo has both projects wired together.

Requirements#

  • A Kotlin Multiplatform module with an Android target (com.android.kotlin.multiplatform.library) and iOS targets.
  • Compose Multiplatform, for components.
  • A group and a version on the Kotlin Multiplatform project (see Configuration). They are the Maven coordinates that the React Native Android build depends on.
  • A React Native app on the New Architecture, version 0.82 or later. With Expo, use a development build: Expo Go cannot load native code.
  • mavenCentral() declared in your repositories: the plugin resolves its annotations and KSP processor from them.

Project layout#

The steps assume the Kotlin Multiplatform project next to the React Native app, with the module named shared:

text
my-app/
├── kmp/                              KMP Gradle project
│   └── shared/                       KMP module
└── react-native/                     React Native app
    └── packages/react-native-kmp/    generated by the plugin

The generated package must be inside the React Native app. Why is explained in the plugin README.

First build#

  1. Apply the Gradle plugin to the KMP module and set its package directory and Maven coordinates.
  2. Export a Kotlin function or Compose component, then generate and install the package.
  3. Import the generated exports in an existing React Native route. The import uses the configured packageName.
tsx
import { GreetingView, sayHello } from 'react-native-kmp';

export default function Screen() {
  console.log(sayHello('React Native'));
  return <GreetingView style={{ flex: 1 }} greeting="Hello" onTap={() => console.log('tap')} />;
}

Run the app#

bash
npm run android   # expo run:android
npm run ios       # expo run:ios

Without Expo, use npx react-native run-android and npx react-native run-ios.

What you should see: the app starts as usual, and the screen that renders the generated component shows your Compose UI. On Android, the build first publishes the Kotlin module into a local Maven repository, then depends on it. On iOS, Xcode compiles the Kotlin framework through the module's podspec, so the first build is slower.

If a step fails, see Troubleshooting. When adding Compose to a real route, follow the screen migration guide.