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
groupand aversionon 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:
my-app/
├── kmp/ KMP Gradle project
│ └── shared/ KMP module
└── react-native/ React Native app
└── packages/react-native-kmp/ generated by the pluginThe generated package must be inside the React Native app. Why is explained in the plugin README.
First build#
- Apply the Gradle plugin to the KMP module and set its package directory and Maven coordinates.
- Export a Kotlin function or Compose component, then generate and install the package.
- Import the generated exports in an existing React Native route. The import uses the configured
packageName.
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#
npm run android # expo run:android
npm run ios # expo run:iosWithout 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.