Thoughts on React Native from an Android engineer's perspective

1. Dependency Management

Gradle uses Maven under the hood to manage project dependencies. Like most dependency management software, it includes a central repository for downloading dependencies, called Maven Central. Despite being ugly and not user friendly (and not nearly as nice as the NPM website), it gets the job done really well and is a really mature and stable system (and, in my opinion, much better than NPM, but that's beside the point :)).

Don't use dynamic versions on Gradle dependencies.

I urge Facebook to reconsider the decision of not uploading React Native artifacts to Maven Central and start doing it. It would help for a more healthy ecosystem with fewer subtle bugs. Also, Facebook, please stop encouraging people to use dynamic versions. Thank you :)

compile 'com.facebook.react:react-native:0.34.0'
compile 'com.foo:foo:1.0.0'
compile 'com.facebook.react:react-native:0.35.0'

Gradle trickery

You can work around version conflicts by using a few tricks. Here are my favorites:

compile('com.foo:foo:1.0.0') {
exclude module: 'react-native'
}
compile('com.foo:foo:1.0.0') {
transitive = false
}
configurations.all {
resolutionStrategy {
force 'com.facebook.react:react-native:0.34.0'
}
}

2. Library project template

Right now, creating a library for React Native is complicated. There is no standard project structure or guide/generator on how to do that. We had (and still have) lots of problems with react-native-maps, especially when working with the "example" app. Most of them come from React Native's directory structure convention, where it expects two sibling directories: android and ios. This leaves no space for a sample app, requiring a completely separate structure for that, with its own package.json and node_modules. Since the sample app needs to depend on the actual library code in order to work, this creates a weird problem where it's really hard to get the paths right. Also making changes to the library JavaScript code and having them reflect in the sample app is hard because it requires getting them into the sample node_modules directory.

Conclusion

With this article/rant, I'm hoping to clear up any misconceptions with Gradle and how it interacts with React Native as well as trying to raise awareness of these issues so that they can be addressed by the Facebook and the community. Unfortunately, some of these issues can only be addressed by Facebook, since other people cannot upload artifacts to Maven Central on their behalf, for example.

--

--

Brazilian, Gaúcho and Software Engineer at Stripe

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store