Can you add libraries with native dependencies to an Expo react native project?

MonkeyBonkey picture MonkeyBonkey · Jan 11, 2017 · Viewed 9k times · Source

Can you use libraries like https://github.com/tolu360/react-native-google-places in an Expo project? I assume any npm library is ok to add, but what about libraries like this google places picker that requires post install steps to link the native projects. Are they supported with Expo?

Answer

ide picture ide · Mar 7, 2017

Regular Expo projects are written only in JavaScript and don't support npm packages that contain Objective-C or Java. However, Expo provides an advanced SDK called ExpoKit for when you absolutely need to use custom native code. From the Expo docs:

Normally, Expo apps are written in pure JS and never “drop down” to the native iOS or Android layer. This is core to the Expo philosophy and it’s part of what makes Expo fast and powerful to use.

However, there are some cases where advanced developers need native capabilities outside of what Expo offers out-of-the-box. The most common situation is when a project requires a specific Native Module which is not supported by React Native Core or the Expo SDK.

You could "detach" your Expo project to create Xcode and Android Studio projects that contain ExpoKit. Then you would add custom Objective-C or Java the same way as with any other Xcode or Android Studio project.

However, the Expo docs also warn about some of the downsides of writing custom native code; many features often can be implemented well in JS, allowing you to retain all of the benefits of a standard Expo project.

Warning: We discourage most of our developers from taking this route, as we believe almost everything you need to do is better accomplished in a cross-platform way with JS.

Writing in JS enables you to best take advantage of over-the-air code deployment and benefit from ongoing updates and support from Expo. You should only do this if you have a particular demand from native code which Expo won’t do a good job supporting, such as (for example) specialized CPU-intensive video processing that must happen locally on the device.