React-native: [META] Build with Clang (Android)

Created on 23 Jul 2018  路  6Comments  路  Source: facebook/react-native

For Discussion

The purpose of this issue is to create a "single point of truth" regarding the efforts related to building React Native using Clang and against libc++, in order to coordinate and recap all the efforts connected to this subject.

Background

Android NDK is about to drop GCC and GNU STL support in favor of Clang and libc++ in version 18. Below are notable changes in NDK

Version 11

  • GCC in the NDK is now deprecated in favor of Clang. We strongly recommend switching to Clang.

Version 13

  • GCC is no longer supported. It will not be removed from the NDK just yet, but is no longer receiving backports. It cannot be removed until after libc++ has become stable enough to be the default, as some parts of gnustl are still incompatible with Clang. It will likely be removed after that point.
  • NDK_TOOLCHAIN_VERSION now defaults to Clang.

Version 14

  • This release ends active support for GCC

Version 16

  • libc++ is out of beta and is now the preferred STL in the NDK. Starting in r17, libc++ is the default STL for CMake and standalone toolchains. If you manually selected a different STL, we strongly encourage you to move to libc++. For more details, see this blog post.

Version 17

  • GCC is no longer supported. It will be removed in NDK r18.
  • libc++ is now the default STL for CMake and standalone toolchains
    gnustl and stlport are deprecated and will be removed in NDK r18.

Documentations

TODO

  • Use CMake to build C++ code
  • Upgrade Folly (https://github.com/facebook/react-native/issues/20302)
  • Compile RN using Clang
  • Compile JSC and RN using Clang against libc++, because gnustl and libc++ ABI are incompatible

How to

Compile with Clang

Open ReactAndroid/src/main/jni/Application.mk and remove or comment out NDK_TOOLCHAIN_VERSION

Compile with against libc++

Open ReactAndroid/src/main/jni/Application.mk and set APP_STL := c++_shared

Related issues

Related PRs

Android Locked Discussion

Most helpful comment

All 6 comments

I was able to compile RN with NDK r17, and will create a PR once https://github.com/facebook/react-native/pull/19945 is merged.

Amazing job锛宼hanks.

If I understood correctly, iOS builds with clang agains libc++ and with almost the same native dependencies. So it won't be a big problem to build with Clang, but to use libc++ we may need to build JSC against it. Please correct me if wrong

I'm not that proficient in C++ and don't know much about RN internals, therefore cannot make changes to C++ code to make it compile with Clang. @hramos could you please find someone from Facebook to help with it.

RN master now use clang

Was this page helpful?
0 / 5 - 0 ratings