Skip to content

Commit

Permalink
feat: add android implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Dec 1, 2023
1 parent 3f4496c commit 6046271
Show file tree
Hide file tree
Showing 12 changed files with 3,883 additions and 31 deletions.
29 changes: 29 additions & 0 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.4.1)

set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)

# set the base libsodium build directory
set(LIBSODIUM_BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/../libsodium/build)

# set the libsodium build directory depending on the target abi
if (${ANDROID_ABI} STREQUAL arm64-v8a)
set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-armv8-a+crypto)
elseif(${ANDROID_ABI} STREQUAL armeabi-v7a)
set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-armv7-a)
elseif(${ANDROID_ABI} STREQUAL x86)
set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-i686)
else()
set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-westmere)
endif()

add_library(sodium SHARED IMPORTED)
include_directories(${LIBSODIUM_BUILD_DIR}/include/)
set_target_properties(sodium PROPERTIES IMPORTED_LOCATION ${LIBSODIUM_BUILD_DIR}/lib/libsodium.so)

# define library target "sodium-jni"
# which will be built from the listed source files
add_library(sodium-jni SHARED src/main/cpp/sodium-jni.c)

# link the sodium lib with our library target
target_link_libraries(sodium-jni sodium)
34 changes: 33 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ android {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

}

buildFeatures {
buildConfig true
}

buildTypes {
Expand All @@ -61,6 +67,12 @@ android {
}
}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}

lintOptions {
disable "GradleCompatible"
}
Expand All @@ -69,18 +81,38 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/newarch",
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/generated/source/codegen/java"
]
} else {
java.srcDirs += ["src/oldarch"]
}
}
}
}

repositories {
mavenCentral()
google()
}


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:+"
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "SodiumReactNative"
codegenJavaPackageName = "com.sodiumreactnative"
}
}
Loading

0 comments on commit 6046271

Please sign in to comment.