diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt index 10b6cf2e8..365532b40 100644 --- a/native/android/app/CMakeLists.txt +++ b/native/android/app/CMakeLists.txt @@ -1,84 +1,85 @@ # For more information about using CMake with Android Studio, read the # documentation: https://d.android.com/studio/projects/add-native-code.html # Sets the minimum version of CMake required to build the native library. cmake_minimum_required(VERSION 3.4.1) # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. set(PACKAGE_NAME "comm_jni_module") find_package(fbjni REQUIRED CONFIG) include_directories( ../../node_modules/react-native/React ../../node_modules/react-native/React/Base ../../node_modules/react-native/ReactCommon ../../node_modules/react-native/ReactCommon/jsi ../../node_modules/react-native/ReactCommon/callinvoker ../../node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon - ../../node_modules/react-native/ReactCommon/turbomodule/core # sqlite code ../../node_modules/@nozbe/sqlite/sqlite-amalgamation-3310100 ../../cpp/lib/sqlite_orm + # symlinked React Native headers + ../headers # folly ./build/third-party-ndk/folly # comm android specific code ./src/cpp # comm native mutual code ../../cpp/CommonCpp/NativeModules ../../cpp/CommonCpp/DatabaseManagers ../../cpp/CommonCpp/Tools ) # search for all cpp files in this directory file(GLOB SQLITE "../../node_modules/@nozbe/sqlite/sqlite-amalgamation-3310100/*.c") file(GLOB COMMON_NATIVE_CODE "../../cpp/CommonCpp/**/*.cpp") file(GLOB ANDROID_NATIVE_CODE "./src/cpp/*.cpp") add_library( # Sets the name of the library. ${PACKAGE_NAME} # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ../../node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp ../../node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/CallInvokerHolder.cpp ../../node_modules/react-native/ReactCommon/turbomodule/core/TurboModule.cpp ../../node_modules/react-native/ReactCommon/turbomodule/core/LongLivedObject.cpp ../../node_modules/react-native/ReactCommon/turbomodule/core/TurboModuleUtils.cpp ${SQLITE} # comm code ${ANDROID_NATIVE_CODE} ${COMMON_NATIVE_CODE} ) add_definitions( -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 ) find_library(log-lib log) target_link_libraries( ${PACKAGE_NAME} fbjni::fbjni android ${log-lib} ) # add a dummy library which is required by CallInvokerHolderImpl.java add_library( turbomodulejsijni # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ./src/cpp/dummy.cpp ) diff --git a/native/android/headers/ReactCommon b/native/android/headers/ReactCommon new file mode 120000 index 000000000..24b9dffe6 --- /dev/null +++ b/native/android/headers/ReactCommon @@ -0,0 +1 @@ +../../../node_modules/react-native/ReactCommon/turbomodule/core \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp index 2bff3b93d..5f7a50394 100644 --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -1,52 +1,48 @@ #include "CommCoreModule.h" #include "DatabaseManager.h" -#if ANDROID -#include -#else #include -#endif namespace comm { using namespace facebook::react; jsi::String CommCoreModule::getDraft(jsi::Runtime &rt, const jsi::String &key) { std::string keyStr = key.utf8(rt); std::string draft = DatabaseManager::getInstance().getDraft(keyStr); return jsi::String::createFromUtf8(rt, draft); } bool CommCoreModule::updateDraft(jsi::Runtime &rt, const jsi::Object &draft) { std::string key = draft.getProperty(rt, "key").asString(rt).utf8(rt); std::string text = draft.getProperty(rt, "text").asString(rt).utf8(rt); DatabaseManager::getInstance().updateDraft(key, text); return true; } jsi::Value CommCoreModule::getAllDrafts(jsi::Runtime &rt) { return createPromiseAsJSIValue( rt, [](jsi::Runtime &innerRt, std::shared_ptr promise) { auto draftsVector = DatabaseManager::getInstance().getAllDrafts(); size_t numDrafts = count_if(draftsVector.begin(), draftsVector.end(), [](Draft draft) { return !draft.text.empty(); }); jsi::Array jsiDrafts = jsi::Array(innerRt, numDrafts); size_t writeIndex = 0; for (Draft draft : draftsVector) { if (draft.text.empty()) { continue; } auto jsiDraft = jsi::Object(innerRt); jsiDraft.setProperty(innerRt, "key", draft.key); jsiDraft.setProperty(innerRt, "text", draft.text); jsiDrafts.setValueAtIndex(innerRt, writeIndex++, jsiDraft); } promise->resolve(std::move(jsiDrafts)); }); } } // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/NativeModules.h b/native/cpp/CommonCpp/NativeModules/NativeModules.h index fcb4d5859..51012a79a 100644 --- a/native/cpp/CommonCpp/NativeModules/NativeModules.h +++ b/native/cpp/CommonCpp/NativeModules/NativeModules.h @@ -1,31 +1,27 @@ /** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @generated by codegen project: GenerateModuleH.js */ #pragma once -#if ANDROID -#include -#else #include -#endif namespace facebook { namespace react { class JSI_EXPORT CommCoreModuleSchemaCxxSpecJSI : public TurboModule { protected: CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker); public: virtual jsi::String getDraft(jsi::Runtime &rt, const jsi::String &key) = 0; virtual bool updateDraft(jsi::Runtime &rt, const jsi::Object &draft) = 0; virtual jsi::Value getAllDrafts(jsi::Runtime &rt) = 0; }; } // namespace react } // namespace facebook diff --git a/patches/comm-react-native-codegen+0.0.7.patch b/patches/comm-react-native-codegen+0.0.7.patch index e9298ce98..0348b4124 100644 --- a/patches/comm-react-native-codegen+0.0.7.patch +++ b/patches/comm-react-native-codegen+0.0.7.patch @@ -1,29 +1,13 @@ diff --git a/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleCpp.js b/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleCpp.js index e5fbfc4..21c8e0b 100644 --- a/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleCpp.js +++ b/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleCpp.js @@ -118,7 +118,7 @@ const FileTemplate = ({libraryName, modules}) => { * ${'@'}generated by codegen project: GenerateModuleH.js */ -#include +#include "NativeModules.h" namespace facebook { namespace react { -diff --git a/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleH.js b/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleH.js -index 99e2030..b70bbaf 100644 ---- a/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleH.js -+++ b/node_modules/comm-react-native-codegen/lib/generators/modules/GenerateModuleH.js -@@ -106,7 +106,11 @@ const FileTemplate = ({modules}) => { - - #pragma once - -+#if ANDROID -+#include -+#else - #include -+#endif - - namespace facebook { - namespace react {