Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix build #116

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,45 @@ cmake_minimum_required(VERSION 3.9.0)

add_subdirectory(../MMKV/Core Core)

set (PACKAGE_NAME "react-native-mmkv")
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

include_directories(
../MMKV/Core
../../react-native/React
../../react-native/React/Base
../../react-native/ReactCommon/jsi
)

add_library(mmkvnative # <-- Library name
add_library(reactnativemmkv # <-- Library name
SHARED
# Provides a relative path to your source file(s).
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
cpp-adapter.cpp
)

set_target_properties(
mmkvnative PROPERTIES
reactnativemmkv PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)

file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")

find_library(
log-lib # Sets the name of the path variable.
log-lib
log
)
find_library(
REACT_NATIVE_JNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

target_link_libraries(
mmkvnative
reactnativemmkv
core
${log-lib}
${REACT_NATIVE_JNI_LIB}
android
)
28 changes: 28 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def getExtOrIntegerDefault(name) {
android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
ndkVersion getExtOrDefault('ndkVersion')

defaultConfig {
minSdkVersion 16
Expand Down Expand Up @@ -56,6 +57,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

configurations {
extractJNI
}
}

repositories {
Expand Down Expand Up @@ -132,4 +137,27 @@ repositories {
dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'

def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
extractJNI(files(rnAAR))
}

task extractJNIFiles {
doLast {
configurations.extractJNI.files.each {
def file = it.absoluteFile

copy {
from zipTree(file)
into "$buildDir/$file.name"
include "jni/**/*"
}
}
}
}

tasks.whenTaskAdded { task ->
if (task.name.contains('externalNativeBuild')) {
task.dependsOn(extractJNIFiles)
}
}
2 changes: 1 addition & 1 deletion android/src/main/java/com/reactnativemmkv/MmkvModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class MmkvModule extends ReactContextBaseJavaModule {
static {
System.loadLibrary("mmkvnative");
System.loadLibrary("reactnativemmkv");
}

private static native void nativeInstall(long jsiPtr, String path);
Expand Down