Skip to content

Commit 000d581

Browse files
authored
Update New Architecture instructions to use CMake instead of Android.mk (facebook#3304)
1 parent d9d4adb commit 000d581

8 files changed

+42
-154
lines changed

docs/new-architecture-app-modules-android.md

Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,20 @@ android {
3232
3333
// Add this block
3434
externalNativeBuild {
35-
ndkBuild {
36-
arguments "APP_PLATFORM=android-21",
37-
"APP_STL=c++_shared",
38-
"NDK_TOOLCHAIN_VERSION=clang",
39-
"GENERATED_SRC_DIR=$buildDir/generated/source",
40-
"PROJECT_BUILD_DIR=$buildDir",
41-
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
42-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
43-
"NODE_MODULES_DIR=$rootDir/../node_modules"
44-
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
45-
cppFlags "-std=c++17"
46-
targets "myapplication_appmodules"
47-
// Fix for windows limit on number of character in file paths and in command lines
48-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
49-
arguments "NDK_APP_SHORT_COMMANDS=true"
50-
}
35+
cmake {
36+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
37+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
38+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
39+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
40+
"-DANDROID_STL=c++_shared"
5141
}
5242
}
5343
}
5444
5545
// Add this block
5646
externalNativeBuild {
57-
ndkBuild {
58-
path "$projectDir/src/main/jni/Android.mk"
47+
cmake {
48+
path "$projectDir/src/main/jni/CMakeLists.txt"
5949
}
6050
}
6151
}
@@ -77,8 +67,8 @@ android {
7767
7868
afterEvaluate {
7969
preBuild.dependsOn(packageReactNdkLibs)
80-
configureNdkBuildDebug.dependsOn(preBuild)
81-
configureNdkBuildRelease.dependsOn(preBuild)
70+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
71+
configureCMakeDebug.dependsOn(preDebugBuild)
8272
}
8373
8474
packagingOptions {
@@ -88,64 +78,16 @@ android {
8878
}
8979
```
9080

91-
Finally, we need to create a Makefile inside the `src/main/jni` folder called `Android.mk` with the following content:
81+
Finally, we need to create a CMake file inside the `src/main/jni` folder called `CMakeLists.txt` with the following content:
9282

93-
```makefile
94-
THIS_DIR := $(call my-dir)
83+
```cmake
84+
cmake_minimum_required(VERSION 3.13)
9585
96-
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
86+
# Define the library name here.
87+
project(myapplication_appmodules)
9788
98-
# If you wish to add a custom TurboModule or Fabric component in your app you
99-
# will have to include the following autogenerated makefile.
100-
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
101-
102-
# Includes the MK file for autolinked libraries
103-
include $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/Android-rncli.mk
104-
105-
include $(CLEAR_VARS)
106-
107-
LOCAL_PATH := $(THIS_DIR)
108-
109-
# You can customize the name of your application .so file here.
110-
LOCAL_MODULE := awesomeapp_appmodules
111-
112-
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni
113-
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/*.cpp)
114-
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni
115-
116-
# If you wish to add a custom TurboModule or Fabric component in your app you
117-
# will have to uncomment those lines to include the generated source
118-
# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni)
119-
#
120-
# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
121-
# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
122-
# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
123-
124-
# Here you should add any native library you wish to depend on.
125-
LOCAL_SHARED_LIBRARIES := \
126-
libfabricjni \
127-
libfbjni \
128-
libfolly_runtime \
129-
libglog \
130-
libjsi \
131-
libreact_codegen_rncore \
132-
libreact_debug \
133-
libreact_nativemodule_core \
134-
libreact_render_componentregistry \
135-
libreact_render_core \
136-
libreact_render_debug \
137-
libreact_render_graphics \
138-
librrc_view \
139-
libruntimeexecutor \
140-
libturbomodulejsijni \
141-
libyoga
142-
143-
# Autolinked libraries
144-
LOCAL_SHARED_LIBRARIES += $(call import-codegen-modules)
145-
146-
LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17
147-
148-
include $(BUILD_SHARED_LIBRARY)
89+
# This file includes all the necessary to let you build your application with the New Architecture.
90+
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)
14991
```
15092

15193
This setup will run a native build on your project and will compile the C++ files that have been generated by the codegen. You will see the native build running with the Gradle task `:app:externalNativeBuildDebug`
@@ -249,7 +191,7 @@ protected constructor(
249191
</TabItem>
250192
</Tabs>
251193

252-
Please note that the `SoLoader.loadLibrary` parameter (in this case `"myapplication_appmodules")` should be the same as the one specified for `LOCAL_MODULE :=` inside the `Android.mk` file you created before.
194+
Please note that the `SoLoader.loadLibrary` parameter (in this case `"myapplication_appmodules")` should be the same as the one specified for `project()` inside the `CMakeLists.txt` file you created before.
253195

254196
This class will then be responsible of loading the TurboModules and will take care of loading the native library build with the NDK at runtime.
255197

docs/new-architecture-app-renderer-android.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ LOG Running "App" with {"fabric":true,"initialProps":{},"rootTag":1}
113113

114114
## Migrating Android ViewManagers
115115

116-
First, make sure you followed the instructions to [Enabling the New Renderer (Fabric) in Your Android Application](#enabling-the-new-renderer-fabric-in-your-android-application). Plus we will also assume that you followed the instructions from [Enabling the New NativeModule System (TurboModule) in Your Android Application](#enabling-the-new-nativemodule-system-turbomodule-in-your-android-application) as the Makefile (`Android.mk`) and other native builds setup steps are presented over there and won’t be repeated here.
116+
First, make sure you followed the instructions to [Enabling the New Renderer (Fabric) in Your Android Application](#enabling-the-new-renderer-fabric-in-your-android-application). Plus we will also assume that you followed the instructions from [Enabling the New NativeModule System (TurboModule) in Your Android Application](#enabling-the-new-nativemodule-system-turbomodule-in-your-android-application) as the native builds setup steps are presented over there and won’t be repeated here.
117117

118118
### JavaScript changes
119119

docs/new-architecture-library-android.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ app/build/generated/source/codegen
3434
│ └── NativeAwesomeManagerSpec.java
3535
├── jni
3636
│ ├── Android.mk
37+
│ ├── CMakeLists.txt
3738
│ ├── react
3839
│ │ └── renderer
3940
│ │ └── components

docs/the-new-architecture/pillars-codegen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ codegen
162162
│ └── MyTurbomodule.java
163163
├── jni
164164
│ ├── Android.mk
165+
│ ├── CMakeLists.txt
165166
│ ├── MyTurbomodule-generated.cpp
166167
│ ├── MyTurbomodule.h
167168
│ └── react

docs/the-new-architecture/pillars-turbomodule.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ codegen
497497
│ └── NativeCalculatorSpec.java
498498
├── jni
499499
│ ├── Android.mk
500+
│ ├── CMakeLists.txt
500501
│ ├── RTNCalculator-generated.cpp
501502
│ ├── RTNCalculator.h
502503
│ └── react

website/versioned_docs/version-0.70/new-architecture-app-modules-android.md

Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,20 @@ android {
3232
3333
// Add this block
3434
externalNativeBuild {
35-
ndkBuild {
36-
arguments "APP_PLATFORM=android-21",
37-
"APP_STL=c++_shared",
38-
"NDK_TOOLCHAIN_VERSION=clang",
39-
"GENERATED_SRC_DIR=$buildDir/generated/source",
40-
"PROJECT_BUILD_DIR=$buildDir",
41-
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
42-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
43-
"NODE_MODULES_DIR=$rootDir/../node_modules"
44-
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
45-
cppFlags "-std=c++17"
46-
targets "myapplication_appmodules"
47-
// Fix for windows limit on number of character in file paths and in command lines
48-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
49-
arguments "NDK_APP_SHORT_COMMANDS=true"
50-
}
35+
cmake {
36+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
37+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
38+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
39+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
40+
"-DANDROID_STL=c++_shared"
5141
}
5242
}
5343
}
5444
5545
// Add this block
5646
externalNativeBuild {
57-
ndkBuild {
58-
path "$projectDir/src/main/jni/Android.mk"
47+
cmake {
48+
path "$projectDir/src/main/jni/CMakeLists.txt"
5949
}
6050
}
6151
}
@@ -77,8 +67,8 @@ android {
7767
7868
afterEvaluate {
7969
preBuild.dependsOn(packageReactNdkLibs)
80-
configureNdkBuildDebug.dependsOn(preBuild)
81-
configureNdkBuildRelease.dependsOn(preBuild)
70+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
71+
configureCMakeDebug.dependsOn(preDebugBuild)
8272
}
8373
8474
packagingOptions {
@@ -88,64 +78,16 @@ android {
8878
}
8979
```
9080

91-
Finally, we need to create a Makefile inside the `src/main/jni` folder called `Android.mk` with the following content:
81+
Finally, we need to create a CMake file inside the `src/main/jni` folder called `CMakeLists.txt` with the following content:
9282

93-
```makefile
94-
THIS_DIR := $(call my-dir)
83+
```cmake
84+
cmake_minimum_required(VERSION 3.13)
9585
96-
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
86+
# Define the library name here.
87+
project(myapplication_appmodules)
9788
98-
# If you wish to add a custom TurboModule or Fabric component in your app you
99-
# will have to include the following autogenerated makefile.
100-
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
101-
102-
# Includes the MK file for autolinked libraries
103-
include $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/Android-rncli.mk
104-
105-
include $(CLEAR_VARS)
106-
107-
LOCAL_PATH := $(THIS_DIR)
108-
109-
# You can customize the name of your application .so file here.
110-
LOCAL_MODULE := awesomeapp_appmodules
111-
112-
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni
113-
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/*.cpp)
114-
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni
115-
116-
# If you wish to add a custom TurboModule or Fabric component in your app you
117-
# will have to uncomment those lines to include the generated source
118-
# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni)
119-
#
120-
# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
121-
# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
122-
# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
123-
124-
# Here you should add any native library you wish to depend on.
125-
LOCAL_SHARED_LIBRARIES := \
126-
libfabricjni \
127-
libfbjni \
128-
libfolly_runtime \
129-
libglog \
130-
libjsi \
131-
libreact_codegen_rncore \
132-
libreact_debug \
133-
libreact_nativemodule_core \
134-
libreact_render_componentregistry \
135-
libreact_render_core \
136-
libreact_render_debug \
137-
libreact_render_graphics \
138-
librrc_view \
139-
libruntimeexecutor \
140-
libturbomodulejsijni \
141-
libyoga
142-
143-
# Autolinked libraries
144-
LOCAL_SHARED_LIBRARIES += $(call import-codegen-modules)
145-
146-
LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17
147-
148-
include $(BUILD_SHARED_LIBRARY)
89+
# This file includes all the necessary to let you build your application with the New Architecture.
90+
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)
14991
```
15092

15193
This setup will run a native build on your project and will compile the C++ files that have been generated by the codegen. You will see the native build running with the Gradle task `:app:externalNativeBuildDebug`
@@ -249,7 +191,7 @@ protected constructor(
249191
</TabItem>
250192
</Tabs>
251193

252-
Please note that the `SoLoader.loadLibrary` parameter (in this case `"myapplication_appmodules")` should be the same as the one specified for `LOCAL_MODULE :=` inside the `Android.mk` file you created before.
194+
Please note that the `SoLoader.loadLibrary` parameter (in this case `"myapplication_appmodules")` should be the same as the one specified for `project()` inside the `CMakeLists.txt` file you created before.
253195

254196
This class will then be responsible of loading the TurboModules and will take care of loading the native library build with the NDK at runtime.
255197

website/versioned_docs/version-0.70/new-architecture-app-renderer-android.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ LOG Running "App" with {"fabric":true,"initialProps":{},"rootTag":1}
113113

114114
## Migrating Android ViewManagers
115115

116-
First, make sure you followed the instructions to [Enabling the New Renderer (Fabric) in Your Android Application](#enabling-the-new-renderer-fabric-in-your-android-application). Plus we will also assume that you followed the instructions from [Enabling the New NativeModule System (TurboModule) in Your Android Application](#enabling-the-new-nativemodule-system-turbomodule-in-your-android-application) as the Makefile (`Android.mk`) and other native builds setup steps are presented over there and won’t be repeated here.
116+
First, make sure you followed the instructions to [Enabling the New Renderer (Fabric) in Your Android Application](#enabling-the-new-renderer-fabric-in-your-android-application). Plus we will also assume that you followed the instructions from [Enabling the New NativeModule System (TurboModule) in Your Android Application](#enabling-the-new-nativemodule-system-turbomodule-in-your-android-application) as the native builds setup steps are presented over there and won’t be repeated here.
117117

118118
### JavaScript changes
119119

website/versioned_docs/version-0.70/new-architecture-library-android.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ app/build/generated/source/codegen
3434
│ └── NativeAwesomeManagerSpec.java
3535
├── jni
3636
│ ├── Android.mk
37+
│ ├── CMakeLists.txt
3738
│ ├── react
3839
│ │ └── renderer
3940
│ │ └── components

0 commit comments

Comments
 (0)