Skip to content

Commit

Permalink
fix: fix android
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed May 13, 2024
1 parent 1520f72 commit 0f95b49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
37 changes: 9 additions & 28 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,18 @@ static def findNodeModules(baseDir) {
}
basePath = basePath.getParent()
}
throw new GradleException("jsiudp: Failed to find node_modules/ path!")
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
throw new GradleException("Failed to find node_modules/ path!")
}

apply plugin: "com.android.library"


def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["JsiUdp_" + name]
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["JsiUdp_" + name]).toInteger()
}

def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def nodeModules = findNodeModules(projectDir)
logger.warn("jsiudp: node_modules/ found at: ${nodeModules}")
logger.warn("node_modules/ found at: ${nodeModules}")

def sourceBuild = false
def defaultDir
Expand Down Expand Up @@ -203,8 +184,8 @@ android {
prefabPublishing true
}
prefab {
jsiudp {
headers "${project.buildDir}/headers/jsiudp/"
rnhnswlib {
headers "${project.buildDir}/headers/rnhnswlib/"
}
}
}
Expand Down Expand Up @@ -242,7 +223,7 @@ dependencies {
implementation "com.facebook.react:react-native:+"

if (REACT_NATIVE_VERSION < 71) {
logger.warn("jsiudp: Extracting files from AAR (pre RN 0.71)")
logger.warn("Extracting files from AAR (pre RN 0.71)")
//noinspection GradleDynamicVersion
extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
//noinspection GradleDynamicVersion
Expand All @@ -252,14 +233,14 @@ dependencies {
if (!sourceBuild) {
def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
if (REACT_NATIVE_VERSION < 69) {
logger.warn("jsiudp: aar state pre 69. match **/**/*.aar")
logger.warn("aar state pre 69. match **/**/*.aar")
rnAarMatcher = "**/**/*.aar"
} else if (REACT_NATIVE_VERSION >= 71) {
logger.warn("jsiudp: aar state post 70, do nothing")
logger.warn("aar state post 70, do nothing")
return
}
def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }).singleFile
logger.warn("jsiudp: Extracting JNI files (pre RN 0.71) ${rnAAR}")
logger.warn("Extracting JNI files (pre RN 0.71) ${rnAAR}")
extractJNI(files(rnAAR))
}
}
Expand Down Expand Up @@ -325,7 +306,7 @@ if (ENABLE_PREFAB) {
// Package all the cpp code in a flattened directory structure
task prepareHeaders(type: Copy) {
from fileTree('../cpp').filter { it.isFile() }
into "${project.buildDir}/headers/jsiudp/react-native-jsi-udp/"
into "${project.buildDir}/headers/rnhnswlib/react-native-hnswlib/"
includeEmptyDirs = false
}
preBuild.dependsOn(prepareHeaders)
Expand Down
2 changes: 1 addition & 1 deletion android/cpp-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

extern "C"
JNIEXPORT jdouble JNICALL
Java_com_hnswlib_HnswlibModule_nativeinstall(JNIEnv *env, jclass _, jlong jsiPtr, jobject jsCallInvokerHolder) {
Java_com_hnswlib_HnswlibModule_nativeInstall(JNIEnv *env, jclass _, jlong jsiPtr, jobject jsCallInvokerHolder) {
auto runtime { reinterpret_cast<facebook::jsi::Runtime*>(jsiPtr) };
auto jsCallInvoker {
facebook::jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>{
Expand Down
2 changes: 2 additions & 0 deletions example/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

-keep class * { native <methods>; }

0 comments on commit 0f95b49

Please sign in to comment.