Skip to content

Commit

Permalink
android build works
Browse files Browse the repository at this point in the history
  • Loading branch information
boorad committed Aug 14, 2024
1 parent cf4f6e3 commit baf1d01
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 35 deletions.
38 changes: 27 additions & 11 deletions packages/react-native-quick-crypto/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 2 additions & 6 deletions packages/react-native-quick-crypto/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-quick-crypto/android/settings.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <jni.h>

#include "HybridRandom.hpp"
#include "random/HybridRandom.hpp"
#include <NitroModules/HybridObjectRegistry.hpp>

using namespace margelo::nitro::crypto;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<>();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <future>

#include "HybridRandomSpec.hpp"
#include "Utils.hpp"
#include "utils/Utils.hpp"

namespace margelo::crypto {

Expand Down

0 comments on commit baf1d01

Please sign in to comment.