This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Wrap third-party native libraries
Edit page
Learn how to create a simple wrapper around two separate native libraries using Expo Modules API.
Expo modules make it possible to easily use native, external libraries built for Android and iOS in React Native projects. This tutorial focuses on utilizing the Expo Modules API to create radial charts using two similar libraries accessible on both native platforms.
The iOS library is inspired by the Android library, so they both have similar API and functionality. This makes them a good example for this tutorial.

In this video you will learn how to wrap native libraries using Expo Modules API.
1
Create a new module
The following steps assume that the new module is created inside a new Expo project. However, you can create a new module inside an existing project by following the alternative instructions.
Alternatively, you can use the new module as a view inside the existing Expo project directory. Run the following command in your project's directory:
Now, open the newly created modules/expo-radial-chart directory to start editing the native code.
Create a new empty Expo module that can be published on npm and utilized in any Expo app by running the following command:
Tip: If you aren't going to ship this library, press Return for all the prompts to accept the default values in the terminal window.
Now, open the newly created expo-radial-chart directory to start editing the native code.
2
Run the example project
To verify that everything is functioning correctly, let's run the example project.
If you started with an existing Expo project, run the following commands from your Expo project's root directory:
If you started with a new module project, open a terminal window, start the TypeScript compiler to watch for changes, and rebuild the module JavaScript:
In another terminal window, compile and run the example app:
3
Add native dependencies
Add the native dependencies to the module by editing the expo-radial-chart/android/build.gradle and expo-radial-chart/ios/ExpoRadialChart.podspec files:
Are you trying to use a .aar dependency?
Inside the android directory, create another directory called libs and place the .aar file inside it. Then, add the file as a Gradle project from autolinking:
Finally, add the dependency to the dependencies list in the android/build.gradle file, using the dependency's specified name with ${project.name}$ prefix:
Inside the android directory, create another directory called libs and place the .aar file inside it. Then, add the directory as a repository:
Finally, add the dependency to the dependencies list. Instead of the filename, use the package path, which includes the @aar at the end:
Are you trying to use an .xcframework or .framework dependency?
On iOS, you can also use dependencies bundled as a framework by using the vendored_frameworks config option.
Note: The file pattern used to specify the path to the framework is relative to the podspec file, and doesn't support traversing the parent directory (
..), meaning you need to place the framework inside the ios directory (or a subdirectory of ios).
Once the framework is added, make sure that the source_files option file pattern doesn't match any files inside the framework. One way to achieve this is to move your iOS source Swift files (that is ExpoRadialChartView.swift and ExpoRadialChartModule.swift) into a src directory separate from where you placed your framework(s) and update the source_files option to only match the src directory:
Your ios directory should end up with a file structure similar to this:
FrameworksMyFramework.frameworksrcExpoRadialChartView.swiftExpoRadialChartModule.swiftExpoRadialChart.podspec4
Define an API
To use the module in the app, define the types for the props. It accepts a list of series — each with a color and a percentage value.
Since the module isn't implemented for web in this example, let's replace the src/ExpoRadialChartView.web.tsx file:
5
Implement the module on Android
Now you can implement the native functionality by editing the placeholder files with the following changes:
- Create a
PieChartinstance and set itslayoutParamsto match the parent view. Then, add it to the view hierarchy using theaddViewfunction. - Define a
setChartDatafunction that accepts a list ofSeriesobjects. You can iterate over the list, create aPieEntryfor each series and store the colors in a separate list. - Create a
PieDataSet, use it to create aPieDataobject, and set it as data on thePieChartinstance.
You also need to use the Prop function to define the data prop and call the native setChartData function when the prop changes:
6
Implement the module on iOS
Now you can implement the native functionality by editing the placeholder files with the following changes:
- Create a new
PieChartViewinstance and use theaddSubviewfunction to add it to the view hierarchy. - Set the
clipsToBoundsproperty and override thelayoutSubviewsfunction to make sure the chart view is always the same size as the parent view. - Create a
setChartDatafunction that accepts a list of series, creates aPieChartDataSetinstance with the data, and assigns it to thedataproperty of thePieChartViewinstance.
You also need to use the Prop function to define the data prop and call the native setChartData function when the prop changes:
7
Write an example app to use the module
You can update the app inside the src/app directory to test the module. Use the ExpoRadialChartView component to render a pie chart with three slices:
Tip: If you created a new module, make sure to update the import statement to:
import { ExpoRadialChartView } from 'expo-radial-chart';
8
Congratulations! You have created your first simple wrapper around two separate third-party native libraries using Expo Modules API.
Next step
A reference to create native modules using Kotlin and Swift.