-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide the C++/Cmake configuration from user space inside the framework
Summary: This change encapsulates all the NDK configuration logic inside the React Native Gradle Plugin. The changes are additive so that the user can still specify a custom configuration if they wish. So far I've applied the changes to RN Tester. Changes to the template require a bump of the Gradle Plugin NPM package. Changelog: [Android] [Changed] - Hide the C++/Cmake configuration from user space inside the framework Reviewed By: cipolleschi Differential Revision: D40139557 fbshipit-source-id: 013220695791e3d0d458e118de16953e0545c3de
- Loading branch information
1 parent
36c9716
commit c9e6a60
Showing
5 changed files
with
145 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# This CMake file is the default used by apps and is placed inside react-native | ||
# to encapsulate it from user space (so you won't need to touch C++/Cmake code at all on Android). | ||
# | ||
# If you wish to customize it (because you want to manually link a C++ library or pass a custom | ||
# compilation flag) you can: | ||
# | ||
# 1. Copy this CMake file inside the `android/app/src/main/jni` folder of your project | ||
# 2. Copy the OnLoad.cpp (in this same folder) file inside the same folder as above. | ||
# 3. Extend your `android/app/build.gradle` as follows | ||
# | ||
# android { | ||
# // Other config here... | ||
# externalNativeBuild { | ||
# cmake { | ||
# path "src/main/jni/CMakeLists.txt" | ||
# } | ||
# } | ||
# } | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
|
||
# Define the library name here. | ||
project(appmodules) | ||
|
||
# This file includes all the necessary to let you build your application with the New Architecture. | ||
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// This C++ file is part of the default configuration used by apps and is placed | ||
// inside react-native to encapsulate it from user space (so you won't need to | ||
// touch C++/Cmake code at all on Android). | ||
// | ||
// If you wish to customize it (because you want to manually link a C++ library | ||
// or pass a custom compilation flag) you can: | ||
// | ||
// 1. Copy this CMake file inside the `android/app/src/main/jni` folder of your | ||
// project | ||
// 2. Copy the OnLoad.cpp (in this same folder) file inside the same folder as | ||
// above. | ||
// 3. Extend your `android/app/build.gradle` as follows | ||
// | ||
// android { | ||
// // Other config here... | ||
// externalNativeBuild { | ||
// cmake { | ||
// path "src/main/jni/CMakeLists.txt" | ||
// } | ||
// } | ||
// } | ||
|
||
#include <DefaultComponentsRegistry.h> | ||
#include <DefaultTurboModuleManagerDelegate.h> | ||
#include <fbjni/fbjni.h> | ||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||
#include <rncli.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
void registerComponents( | ||
std::shared_ptr<ComponentDescriptorProviderRegistry const> registry) { | ||
// Custom Fabric Components go here. You can register custom | ||
// components coming from your App or from 3rd party libraries here. | ||
// | ||
// providerRegistry->add(concreteComponentDescriptorProvider< | ||
// AocViewerComponentDescriptor>()); | ||
|
||
// By default we just use the components autolinked by RN CLI | ||
rncli_registerProviders(registry); | ||
} | ||
|
||
std::shared_ptr<TurboModule> provideModules( | ||
const std::string &name, | ||
const JavaTurboModule::InitParams ¶ms) { | ||
// Here you can provide your own module provider for TurboModules coming from | ||
// either your application or from external libraries. The approach to follow | ||
// is similar to the following (for a library called `samplelibrary`): | ||
// | ||
// auto module = samplelibrary_ModuleProvider(moduleName, params); | ||
// if (module != nullptr) { | ||
// return module; | ||
// } | ||
// return rncore_ModuleProvider(moduleName, params); | ||
|
||
// By default we just use the module providers autolinked by RN CLI | ||
return rncli_ModuleProvider(name, params); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
facebook::react::DefaultTurboModuleManagerDelegate:: | ||
moduleProvidersFromEntryPoint = &facebook::react::provideModules; | ||
facebook::react::DefaultComponentsRegistry:: | ||
registerComponentDescriptorsFromEntryPoint = | ||
&facebook::react::registerComponents; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters