Skip to content

Commit dfd7f70

Browse files
cortinicofacebook-github-bot
authored andcommitted
Update the new app template to use CMake instead of Android.mk (#34354)
Summary: Pull Request resolved: #34354 This change simplifies the setup for New Architecture for users on Android. Instead of using the Android.mk file, users can now use a CMake file which encapsulate a lot of the complexities and reduces the maintainance cost. Android.mk support is kept for backward compatibility. Changelog: [Android] [Changed] - Update the new app template to use CMake instead of Android.mk Reviewed By: cipolleschi Differential Revision: D38460536 fbshipit-source-id: 9d4c3b15be751921d34023b24c174044537e6f02
1 parent be35c6d commit dfd7f70

File tree

3 files changed

+21
-79
lines changed

3 files changed

+21
-79
lines changed

template/android/app/build.gradle

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,14 @@ android {
143143
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
144144

145145
if (isNewArchitectureEnabled()) {
146-
// We configure the NDK build only if you decide to opt-in for the New Architecture.
146+
// We configure the CMake build only if you decide to opt-in for the New Architecture.
147147
externalNativeBuild {
148-
ndkBuild {
149-
arguments "APP_PLATFORM=android-21",
150-
"APP_STL=c++_shared",
151-
"NDK_TOOLCHAIN_VERSION=clang",
152-
"GENERATED_SRC_DIR=$buildDir/generated/source",
153-
"PROJECT_BUILD_DIR=$buildDir",
154-
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
155-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
156-
"NODE_MODULES_DIR=$rootDir/../node_modules"
157-
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
158-
cppFlags "-std=c++17"
159-
// Make sure this target name is the same you specify inside the
160-
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
161-
targets "helloworld_appmodules"
162-
// Fix for windows limit on number of character in file paths and in command lines
163-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
164-
arguments "NDK_APP_SHORT_COMMANDS=true"
165-
}
148+
cmake {
149+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
150+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
151+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
152+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
153+
"-DANDROID_STL=c++_shared"
166154
}
167155
}
168156
if (!enableSeparateBuildPerCPUArchitecture) {
@@ -176,8 +164,8 @@ android {
176164
if (isNewArchitectureEnabled()) {
177165
// We configure the NDK build only if you decide to opt-in for the New Architecture.
178166
externalNativeBuild {
179-
ndkBuild {
180-
path "$projectDir/src/main/jni/Android.mk"
167+
cmake {
168+
path "$projectDir/src/main/jni/CMakeLists.txt"
181169
}
182170
}
183171
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
@@ -199,15 +187,15 @@ android {
199187
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
200188

201189
// Due to a bug inside AGP, we have to explicitly set a dependency
202-
// between configureNdkBuild* tasks and the preBuild tasks.
190+
// between configureCMakeDebug* tasks and the preBuild tasks.
203191
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
204-
configureNdkBuildRelease.dependsOn(preReleaseBuild)
205-
configureNdkBuildDebug.dependsOn(preDebugBuild)
192+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
193+
configureCMakeDebug.dependsOn(preDebugBuild)
206194
reactNativeArchitectures().each { architecture ->
207-
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
195+
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
208196
dependsOn("preDebugBuild")
209197
}
210-
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
198+
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
211199
dependsOn("preReleaseBuild")
212200
}
213201
}

template/android/app/src/main/jni/Android.mk

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
# Define the library name here.
4+
project(rntester_appmodules)
5+
6+
# This file includes all the necessary to let you build your application with the New Architecture.
7+
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

0 commit comments

Comments
 (0)