Skip to content

Commit

Permalink
Adapt template to new architecture autolinking on Android (#33777)
Browse files Browse the repository at this point in the history
Summary:
Provides necessary changes for the autolinking to work in new architecture on Android. Depends on react-native-community/cli#1603 and is subject to change.

Upgraded the RN CLI to v9.0.0-alpha.0 so that it's testable locally.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Change] - Adapt template to new architecture autolinking on Android

Pull Request resolved: #33777

Test Plan: CI

Reviewed By: cipolleschi

Differential Revision: D36478984

Pulled By: cortinico

fbshipit-source-id: 970fa7bcb77898d9defae18c20026a7783ba4108
  • Loading branch information
thymikee authored and facebook-github-bot committed Jun 24, 2022
1 parent a174530 commit 9ad7cbc
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 67 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
},
"dependencies": {
"@jest/create-cache-key-function": "^27.0.1",
"@react-native-community/cli": "^8.0.0",
"@react-native-community/cli-platform-android": "^8.0.0",
"@react-native-community/cli-platform-ios": "^8.0.0",
"@react-native-community/cli": "^9.0.0-alpha.0",
"@react-native-community/cli-platform-android": "^9.0.0-alpha.0",
"@react-native-community/cli-platform-ios": "^9.0.0-alpha.0",
"@react-native/assets": "1.0.0",
"@react-native/normalize-color": "2.0.0",
"@react-native/polyfills": "2.0.0",
Expand Down
12 changes: 12 additions & 0 deletions template/android/app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
# If you wish to add a custom TurboModule or Fabric component in your app you
# will have to include the following autogenerated makefile.
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk

# Includes the MK file for autolinked libraries
include $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/Android-rncli.mk

include $(CLEAR_VARS)

LOCAL_PATH := $(THIS_DIR)
Expand All @@ -16,6 +20,11 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)

# Autolinked TurboModules and Fabric components
LOCAL_C_INCLUDES += $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni
LOCAL_SRC_FILES += $(wildcard $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/*.cpp)
LOCAL_EXPORT_C_INCLUDES += $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni

# If you wish to add a custom TurboModule or Fabric component in your app you
# will have to uncomment those lines to include the generated source
# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni)
Expand Down Expand Up @@ -43,6 +52,9 @@ LOCAL_SHARED_LIBRARIES := \
libturbomodulejsijni \
libyoga

# Autolinked libraries
LOCAL_SHARED_LIBRARIES += $(call import-codegen-modules)

LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall

include $(BUILD_SHARED_LIBRARY)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MainApplicationModuleProvider.h"

#include <rncli.h>
#include <rncore.h>

namespace facebook {
Expand All @@ -17,6 +18,13 @@ std::shared_ptr<TurboModule> MainApplicationModuleProvider(
// return module;
// }
// return rncore_ModuleProvider(moduleName, params);

// Module providers autolinked by RN CLI
auto rncli_module = rncli_ModuleProvider(moduleName, params);
if (rncli_module != nullptr) {
return rncli_module;
}

return rncore_ModuleProvider(moduleName, params);
}

Expand Down
4 changes: 4 additions & 0 deletions template/android/app/src/main/jni/MainComponentsRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/rncore/ComponentDescriptors.h>
#include <rncli.h>

namespace facebook {
namespace react {
Expand All @@ -14,6 +15,9 @@ std::shared_ptr<ComponentDescriptorProviderRegistry const>
MainComponentsRegistry::sharedProviderRegistry() {
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();

// Autolinked providers registered by RN CLI
rncli_registerProviders(providerRegistry);

// Custom Fabric Components go here. You can register custom
// components coming from your App or from 3rd party libraries here.
//
Expand Down
128 changes: 64 additions & 64 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1087,22 +1087,22 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@react-native-community/cli-clean@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-8.0.0.tgz#c8fc6e8d6a84c90ca0839d48080a87ad455613db"
integrity sha512-VY/kwyH5xp6oXiB9bcwa+I9W5k6WR/nX3s85FuMW76hSlgG1UVAGL04uZPwYlSmMZuSOSuoXOaIjJ7wAvQMBpg==
"@react-native-community/cli-clean@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-9.0.0-alpha.0.tgz#cdd42633984785130bb9baed14d8349fa0de4615"
integrity sha512-YUnkQYg8of3R9em7n6Gp3DSyeIPaifvVlJwFgHnL8h6Zm6rWj+Zf7u9xs3CV9fO4y+a5zXcqZsxCKFjnvvfE0w==
dependencies:
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
chalk "^4.1.2"
execa "^1.0.0"
prompts "^2.4.0"

"@react-native-community/cli-config@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-config/-/cli-config-8.0.0.tgz#1d464165995ac587b15484d5a0e6ba262b9fe398"
integrity sha512-SrxfySVwCv1BkMHGrl6i9UkZe1VsCDpoWehPSDY46bl5o78MrjKcaMkYDJJlPxIdXr3eUjKToaay1ge26SXhVg==
"@react-native-community/cli-config@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-config/-/cli-config-9.0.0-alpha.0.tgz#9bc40b9beb8f8e20526e4439dd5be603dc07e351"
integrity sha512-c9B8W1okaSOp9f+8vLA0yfMOTZlhZms3Lhjq7/6DGvakg2Wazwn9YzhDB6RGDAjHQlfY5T4Gp5JkwZEV1IlVww==
dependencies:
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
cosmiconfig "^5.1.0"
deepmerge "^3.2.0"
glob "^7.1.3"
Expand All @@ -1115,14 +1115,14 @@
dependencies:
serve-static "^1.13.1"

"@react-native-community/cli-doctor@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-doctor/-/cli-doctor-8.0.0.tgz#97e884bdc41863f9a70736acd21f8d1fc8d1337d"
integrity sha512-3lEX0yyXXyVMqkAc+mW2WRXyGuTD8ozaouGakt/5ooTdSI9riWNWb/QUua821EBrBj+r1YV80p5zVZQSpQQHwQ==
"@react-native-community/cli-doctor@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-doctor/-/cli-doctor-9.0.0-alpha.0.tgz#f9ed434d55962d2664d30ddd2065136fc5eff268"
integrity sha512-C5OdlvGysFQKW5kPgQewLcpdWok4wz9ocqpShO/bcpbs7sJZPs/QvqqVvuKY83iRCTEbkeqelZ9EEsPLYKtmRQ==
dependencies:
"@react-native-community/cli-config" "^8.0.0"
"@react-native-community/cli-platform-ios" "^8.0.0"
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-config" "^9.0.0-alpha.0"
"@react-native-community/cli-platform-ios" "^9.0.0-alpha.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
chalk "^4.1.2"
command-exists "^1.2.8"
envinfo "^7.7.2"
Expand All @@ -1137,23 +1137,23 @@
sudo-prompt "^9.0.0"
wcwidth "^1.0.1"

"@react-native-community/cli-hermes@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-hermes/-/cli-hermes-8.0.0.tgz#5cfde0ab2bea18c0e36b72ef84b5fcc4a87a7664"
integrity sha512-vDwPQ9a4ye3CENqcI3KTRgVXwbHNS7TnZRfTs2Sqb5j4XiSMpIW0FkEziSDOJqWIAqgrSkbExDpiT/SeWzHOvw==
"@react-native-community/cli-hermes@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-hermes/-/cli-hermes-9.0.0-alpha.0.tgz#3730feca5d2e132b8cedc04c6eb26f3f142bb006"
integrity sha512-yg3JpOIVImFsL6Hpihvu7JeDeiF0mQMcqMIE0+xl6wmElSrbBuSLqS3bc8r0araN133ExbOWGyqg64WEQCgtQg==
dependencies:
"@react-native-community/cli-platform-android" "^8.0.0"
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-platform-android" "^9.0.0-alpha.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
chalk "^4.1.2"
hermes-profile-transformer "^0.0.6"
ip "^1.1.5"

"@react-native-community/cli-platform-android@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-8.0.0.tgz#826a8f4c3e2e31bd281b57e28fc3e1eaca224d2d"
integrity sha512-/1N7G3ZMoJi6OAzopFOWOcCLWbVBn6T1Hmjk+XXCEkgmbK34MRTxYGZur8TCOaQmueKSfLDbFtlVJr5Et4sxWQ==
"@react-native-community/cli-platform-android@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-9.0.0-alpha.0.tgz#1179012ea6da931746e1bf575aec328ed56f3741"
integrity sha512-BffjB3IklNdQOybi2ZhEqtveVHLCwwf/V7caMDPvyzcPuaxokr/id5I4BRdqFeHTNxvMt7fhw43ktQOOUv/jRQ==
dependencies:
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
chalk "^4.1.2"
execa "^1.0.0"
fs-extra "^8.1.0"
Expand All @@ -1163,12 +1163,12 @@
logkitty "^0.7.1"
slash "^3.0.0"

"@react-native-community/cli-platform-ios@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-ios/-/cli-platform-ios-8.0.0.tgz#9f0e30f8f8dbdf214bb0f94bcf66ad30470c6592"
integrity sha512-cWI0VGsovPAqopPKRHExlhtXDuVJzYT1ITsden4M+K6oMRiC/4+PVpEHgkO3ghcPnX7Ee7KGhjmPrB+fvtk/4A==
"@react-native-community/cli-platform-ios@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-ios/-/cli-platform-ios-9.0.0-alpha.0.tgz#516f401af193685ff07c4de7448e3f0e19e842a9"
integrity sha512-b4rZw8ho2jJQ4iYZNKvXmMNSAdYz38enNyWg6/8O5XHRNk0vidhLlgTX0scPHD7Z8sy3cFqv0xqa5HTByBLsUQ==
dependencies:
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
chalk "^4.1.2"
execa "^1.0.0"
glob "^7.1.3"
Expand All @@ -1177,13 +1177,13 @@
ora "^5.4.1"
plist "^3.0.2"

"@react-native-community/cli-plugin-metro@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-plugin-metro/-/cli-plugin-metro-8.0.0.tgz#0b355a7a6fe93b347ec32b3edb3b2cd96b04dfd8"
integrity sha512-eIowV2ZRbzIWL3RIKVUUSahntXTuAeKzBSsFuhffLZphsV+UdKdtg5ATR9zbq7nsKap4ZseO5DkVqZngUkC7iQ==
"@react-native-community/cli-plugin-metro@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-plugin-metro/-/cli-plugin-metro-9.0.0-alpha.0.tgz#e4511ab63a111735128ce7cae162676385503555"
integrity sha512-JtMcMk7vpYEXux/Bk+kCx4TexMtNeeWa6BGbjRFFuNpi8GVydJFPYWGVVMUyciGZI30fs6XJtsoRfq3GhxLQbw==
dependencies:
"@react-native-community/cli-server-api" "^8.0.0"
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-server-api" "^9.0.0-alpha.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
chalk "^4.1.2"
metro "^0.70.1"
metro-config "^0.70.1"
Expand All @@ -1193,13 +1193,13 @@
metro-runtime "^0.70.1"
readline "^1.3.0"

"@react-native-community/cli-server-api@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-server-api/-/cli-server-api-8.0.0.tgz#562fee6da9f880531db2af1d3439efb7309281f8"
integrity sha512-TxUs3sMl9clt7sdv30XETc6VRzyaEli2vDrk3TB5W5o5nSd1PmQdP4ccdGLO/nDRXwOy72QmmXlYWMg1XGU0Gg==
"@react-native-community/cli-server-api@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-server-api/-/cli-server-api-9.0.0-alpha.0.tgz#f4abcfcdd2e1a6ff97e5a95fa88288178b9d08c6"
integrity sha512-hDZDSTNLiva0vvFNxMz6pfhxKSR9+8IS3KyjLI5wQHYb3lkJJofUjCnbqzg+zJPGWs21JPv1HBIBbDfZ8KJEAQ==
dependencies:
"@react-native-community/cli-debugger-ui" "^8.0.0"
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
compression "^1.7.1"
connect "^3.6.5"
errorhandler "^1.5.0"
Expand All @@ -1208,10 +1208,10 @@
serve-static "^1.13.1"
ws "^7.5.1"

"@react-native-community/cli-tools@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-8.0.0.tgz#2ca9177d7cdf352f6863f278cdacd44066d10473"
integrity sha512-jA4y8CebrRZaOJFjc5zMOnls4KfHkBl2FUtBZV2vcWuedQHa6JVwo+KO88ta3Ysby3uY0+mrZagZfXk7c0mrBw==
"@react-native-community/cli-tools@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-9.0.0-alpha.0.tgz#ec0d93301b55579ca05a7a27d23eaa9b3236578f"
integrity sha512-WUQlC016n6oY3PW1RTRacYqoFN1Omfq+pyglDlCFuMOfUA07ubmcAryGeJTldZOW3+jwyEOwWBNYEMrhowZc9A==
dependencies:
appdirsjs "^1.2.4"
chalk "^4.1.2"
Expand All @@ -1223,27 +1223,27 @@
semver "^6.3.0"
shell-quote "^1.7.3"

"@react-native-community/cli-types@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-types/-/cli-types-8.0.0.tgz#72d24178e5ed1c2d271da43e0a4a4f59178f261a"
integrity sha512-1lZS1PEvMlFaN3Se1ksyoFWzMjk+YfKi490GgsqKJln9gvFm8tqVPdnXttI5Uf2DQf3BMse8Bk8dNH4oV6Ewow==
"@react-native-community/cli-types@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-types/-/cli-types-9.0.0-alpha.0.tgz#b0809b868e1a2a0c326a0f218abdbb8ff7744272"
integrity sha512-pnQVEN9XcYfqIPKwRbzv5HRH3aEjyJYr3V2cOPOaCMuAKU1tWdHXakY1zfui1jTiQG6h6hOkmmMjr3j2vY1ndQ==
dependencies:
joi "^17.2.1"

"@react-native-community/cli@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli/-/cli-8.0.0.tgz#f6dd0c7332174ca327c06e9164fabb3a03d202d3"
integrity sha512-wkbIcUixdFBHF9tNo+ErGypKLQ/hZ8Ww13IPhOgZtPo58/j+e902kqEeXRRBUlvbLMBAWBxFmVKxEdIb9ZvTpA==
"@react-native-community/cli@^9.0.0-alpha.0":
version "9.0.0-alpha.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli/-/cli-9.0.0-alpha.0.tgz#26aed6dba651c5360bfc83862e2b04f44af3d4da"
integrity sha512-rSdYHDnBSTV4BvXkoL0jeGWcD3zAqdrkp9LAkrUuZvxltyE04OArfcWCB2AasgMiVUd7u63tGnafGgqRgAKBqw==
dependencies:
"@react-native-community/cli-clean" "^8.0.0"
"@react-native-community/cli-config" "^8.0.0"
"@react-native-community/cli-clean" "^9.0.0-alpha.0"
"@react-native-community/cli-config" "^9.0.0-alpha.0"
"@react-native-community/cli-debugger-ui" "^8.0.0"
"@react-native-community/cli-doctor" "^8.0.0"
"@react-native-community/cli-hermes" "^8.0.0"
"@react-native-community/cli-plugin-metro" "^8.0.0"
"@react-native-community/cli-server-api" "^8.0.0"
"@react-native-community/cli-tools" "^8.0.0"
"@react-native-community/cli-types" "^8.0.0"
"@react-native-community/cli-doctor" "^9.0.0-alpha.0"
"@react-native-community/cli-hermes" "^9.0.0-alpha.0"
"@react-native-community/cli-plugin-metro" "^9.0.0-alpha.0"
"@react-native-community/cli-server-api" "^9.0.0-alpha.0"
"@react-native-community/cli-tools" "^9.0.0-alpha.0"
"@react-native-community/cli-types" "^9.0.0-alpha.0"
chalk "^4.1.2"
commander "^2.19.0"
execa "^1.0.0"
Expand Down

0 comments on commit 9ad7cbc

Please sign in to comment.