From baf1d015bc3376caecaf907a8431ce27504bb00b Mon Sep 17 00:00:00 2001 From: Brad Anderson Date: Wed, 14 Aug 2024 11:01:59 -0400 Subject: [PATCH] android build works --- .../android/CMakeLists.txt | 38 +++++++++++++------ .../android/build.gradle | 8 +--- .../android/settings.gradle | 2 - .../android/src/main/cpp/cpp-adapter.cpp | 2 +- ...ckage.not-used => QuickCryptoPackage.java} | 27 +++++++------ .../cpp/random/HybridRandom.hpp | 2 +- 6 files changed, 44 insertions(+), 35 deletions(-) delete mode 100644 packages/react-native-quick-crypto/android/settings.gradle rename packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/{QuickCryptoPackage.not-used => QuickCryptoPackage.java} (59%) diff --git a/packages/react-native-quick-crypto/android/CMakeLists.txt b/packages/react-native-quick-crypto/android/CMakeLists.txt index dd4f5d26..71f2899e 100644 --- a/packages/react-native-quick-crypto/android/CMakeLists.txt +++ b/packages/react-native-quick-crypto/android/CMakeLists.txt @@ -1,28 +1,44 @@ -project(QuickCrypto) cmake_minimum_required(VERSION 3.9.0) +project(QuickCrypto) set(PACKAGE_NAME QuickCrypto) + set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_CXX_STANDARD 20) -# Add Nitrogen specs :) -include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/QuickCrypto+autolinking.cmake) - -# Third party libraries (Prefabs) -find_library(LOG_LIB log) -find_library(REACT_NATIVE_SCREENS_LIB rnscreens) - # Define C++ library and add all sources add_library( ${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp - ../cpp/HybridRandom.cpp + ../cpp/random/HybridRandom.cpp ) +include_directories(../cpp) +include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/QuickCrypto+autolinking.cmake) + +# Third party libraries (Prefabs) +find_library(LOG_LIB log) + +find_package(ReactAndroid REQUIRED CONFIG) +find_package(fbjni REQUIRED CONFIG) +find_package(openssl REQUIRED CONFIG) + # Link all libraries together target_link_libraries( ${PACKAGE_NAME} ${LOG_LIB} # <-- Logcat logger - ${REACT_NATIVE_SCREENS_LIB} # <-- React Native Screens android # <-- Android core -) + fbjni::fbjni # <-- Facebook C++ JNI helpers + openssl::crypto # <-- OpenSSL (Crypto) + ReactAndroid::jsi + ReactAndroid::turbomodulejsijni + ReactAndroid::react_nativemodule_core + ReactAndroid::react_render_core + ReactAndroid::runtimeexecutor + ReactAndroid::fabricjni + ReactAndroid::react_debug + ReactAndroid::react_render_core + ReactAndroid::react_render_componentregistry + ReactAndroid::rrc_view + ReactAndroid::folly_runtime + ) diff --git a/packages/react-native-quick-crypto/android/build.gradle b/packages/react-native-quick-crypto/android/build.gradle index 559594be..6e511dc7 100644 --- a/packages/react-native-quick-crypto/android/build.gradle +++ b/packages/react-native-quick-crypto/android/build.gradle @@ -99,13 +99,9 @@ repositories { dependencies { - // For < 0.71, this will be from the local maven repo - // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin - //noinspection GradleDynamicVersion - implementation "com.facebook.react:react-native:+" - - // Add a dependency on NitroModules + implementation "com.facebook.react:react-native" implementation project(":react-native-nitro-modules") + implementation "com.android.ndk.thirdparty:openssl:1.1.1q-beta-1" } if (isNewArchitectureEnabled()) { diff --git a/packages/react-native-quick-crypto/android/settings.gradle b/packages/react-native-quick-crypto/android/settings.gradle deleted file mode 100644 index ee815efd..00000000 --- a/packages/react-native-quick-crypto/android/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'QuickCrypto' -project(':react-native-nitro-modules').projectDir = new File(rootProject.projectDir, '../../node_modules/react-native-nitro-modules/android') diff --git a/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp b/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp index c73e0f0e..92b486be 100644 --- a/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp +++ b/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp @@ -1,6 +1,6 @@ #include -#include "HybridRandom.hpp" +#include "random/HybridRandom.hpp" #include using namespace margelo::nitro::crypto; diff --git a/packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.not-used b/packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java similarity index 59% rename from packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.not-used rename to packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java index 47850bb7..04633b7f 100644 --- a/packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.not-used +++ b/packages/react-native-quick-crypto/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java @@ -1,39 +1,38 @@ package com.margelo.nitro.quickcrypto; import android.util.Log; - import androidx.annotation.Nullable; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.module.model.ReactModuleInfoProvider; import com.facebook.react.TurboReactPackage; -import com.margelo.nitro.HybridObject; -import com.margelo.nitro.HybridObjectRegistry; import java.util.HashMap; -import java.util.function.Supplier; public class QuickCryptoPackage extends TurboReactPackage { + private static final String TAG = "QuickCrypto"; + static { + try { + Log.i(TAG, "Loading C++ library..."); + System.loadLibrary(TAG); + Log.i(TAG, "Successfully loaded C++ library!"); + } catch (Throwable e) { + Log.e(TAG, "Failed to load C++ library! Is it properly installed and linked?", e); + throw e; + } + } + @Nullable @Override public NativeModule getModule(String name, ReactApplicationContext reactContext) { return null; } - public QuickCryptoPackage() { - HybridObjectRegistry.registerHybridObjectConstructor("HybridRandom", () -> { - Log.i("YEET", "initializing Random..."); - HybridObject obj = new HybridObject(new Random()); - Log.i("YEET", "done Random!"); - return f; - }); - } - @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { return () -> { - return new HashMap<>(); + return new HashMap<>(); }; } } diff --git a/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp b/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp index 234d82d8..28f54ae2 100644 --- a/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp +++ b/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp @@ -3,7 +3,7 @@ #include #include "HybridRandomSpec.hpp" -#include "Utils.hpp" +#include "utils/Utils.hpp" namespace margelo::crypto {