fix: Fix java.lang.NoSuchMethodError
error for .toArrayList()
(#322)
* fix: Fix `java.lang.NoSuchMethodError` error for `.toArrayList()` * Fix `HashMap<K, V>` conversion to `jsi::Object` * Update FRAME_PROCESSORS_CREATE_OVERVIEW.mdx
This commit is contained in:
parent
c5979688c8
commit
b493576373
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include "java-bindings/JImageProxyHostObject.h"
|
#include "java-bindings/JImageProxyHostObject.h"
|
||||||
#include "java-bindings/JImageProxy.h"
|
#include "java-bindings/JImageProxy.h"
|
||||||
#include "java-bindings/JReadableArray.h"
|
|
||||||
#include "java-bindings/JReadableMap.h"
|
|
||||||
#include "java-bindings/JArrayList.h"
|
#include "java-bindings/JArrayList.h"
|
||||||
#include "java-bindings/JHashMap.h"
|
#include "java-bindings/JHashMap.h"
|
||||||
|
|
||||||
@ -128,59 +126,58 @@ jsi::Value JSIJNIConversion::convertJNIObjectToJSIValue(jsi::Runtime &runtime, c
|
|||||||
|
|
||||||
return jsi::String::createFromUtf8(runtime, object->toString());
|
return jsi::String::createFromUtf8(runtime, object->toString());
|
||||||
|
|
||||||
} else if (object->isInstanceOf(JReadableArray::javaClassStatic())) {
|
} else if (object->isInstanceOf(JArrayList<jobject>::javaClassStatic())) {
|
||||||
// ReadableArray
|
// ArrayList<E>
|
||||||
|
|
||||||
static const auto toArrayListFunc = JReadableArray::javaClassLocal()->getMethod<jni::JArrayClass<jobject>()>("toArrayList");
|
auto arrayList = static_ref_cast<JArrayList<jobject>>(object);
|
||||||
|
auto size = arrayList->size();
|
||||||
auto array = toArrayListFunc(object.get());
|
|
||||||
auto size = array->size();
|
|
||||||
|
|
||||||
auto result = jsi::Array(runtime, size);
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
|
||||||
result.setValueAtIndex(runtime, i, convertJNIObjectToJSIValue(runtime, (*array)[i]));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} else if (object->isInstanceOf(JArrayList::javaClassStatic())) {
|
|
||||||
// ArrayList
|
|
||||||
|
|
||||||
static const auto iteratorFunc = JArrayList::javaClassLocal()->getMethod<jni::JIterator<jobject>()>("iterator");
|
|
||||||
static const auto sizeFunc = JArrayList::javaClassLocal()->getMethod<jint()>("size");
|
|
||||||
|
|
||||||
auto iterator = iteratorFunc(object.get());
|
|
||||||
auto size = sizeFunc(object.get());
|
|
||||||
|
|
||||||
auto result = jsi::Array(runtime, size);
|
auto result = jsi::Array(runtime, size);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (auto& item : *iterator) {
|
for (const auto& item : *arrayList) {
|
||||||
result.setValueAtIndex(runtime, i, convertJNIObjectToJSIValue(runtime, item));
|
result.setValueAtIndex(runtime, i, convertJNIObjectToJSIValue(runtime, item));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} else if (object->isInstanceOf(JReadableMap::javaClassStatic())) {
|
} else if (object->isInstanceOf(react::ReadableArray::javaClassStatic())) {
|
||||||
// ReadableMap
|
// ReadableArray
|
||||||
|
|
||||||
static const auto toHashMapFunc = JReadableMap::javaClassLocal()->getMethod<jni::JHashMap<jstring, jobject>()>("toHashMap");
|
static const auto toArrayListFunc = react::ReadableArray::javaClassLocal()->getMethod<JArrayList<jobject>()>("toArrayList");
|
||||||
auto hashMap = toHashMapFunc(object.get());
|
|
||||||
|
// call recursive, this time ArrayList<E>
|
||||||
|
auto array = toArrayListFunc(object.get());
|
||||||
|
return convertJNIObjectToJSIValue(runtime, array);
|
||||||
|
|
||||||
|
} else if (object->isInstanceOf(jni::JHashMap<jstring, jobject>::javaClassStatic())) {
|
||||||
|
// HashMap<K, V>
|
||||||
|
|
||||||
|
auto map = static_ref_cast<jni::JHashMap<jstring, jobject>>(object);
|
||||||
|
|
||||||
auto result = jsi::Object(runtime);
|
auto result = jsi::Object(runtime);
|
||||||
|
for (const auto& entry : *map) {
|
||||||
for (const auto& entry : *hashMap) {
|
|
||||||
auto key = entry.first->toString();
|
auto key = entry.first->toString();
|
||||||
auto value = entry.second;
|
auto value = entry.second;
|
||||||
auto jsiValue = convertJNIObjectToJSIValue(runtime, value);
|
auto jsiValue = convertJNIObjectToJSIValue(runtime, value);
|
||||||
result.setProperty(runtime, key.c_str(), jsiValue);
|
result.setProperty(runtime, key.c_str(), jsiValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
} else if (object->isInstanceOf(react::ReadableMap::javaClassStatic())) {
|
||||||
|
// ReadableMap
|
||||||
|
|
||||||
|
static const auto toHashMapFunc = react::ReadableMap::javaClassLocal()->getMethod<jni::JHashMap<jstring, jobject>()>("toHashMap");
|
||||||
|
|
||||||
|
// call recursive, this time HashMap<K, V>
|
||||||
|
auto hashMap = toHashMapFunc(object.get());
|
||||||
|
return convertJNIObjectToJSIValue(runtime, hashMap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto type = object->getClass()->toString();
|
auto type = object->getClass()->toString();
|
||||||
auto message = "Received unknown JNI type \"" + type + "\"! Cannot convert to jsi::Value.";
|
auto message = "Received unknown JNI type \"" + type + "\"! Cannot convert to jsi::Value.";
|
||||||
__android_log_write(ANDROID_LOG_ERROR, "VisionCamera", message.c_str());
|
__android_log_write(ANDROID_LOG_ERROR, "VisionCamera", message.c_str());
|
||||||
return jsi::Value::undefined();
|
throw std::runtime_error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
|
@ -13,8 +13,9 @@ using namespace facebook;
|
|||||||
using namespace jni;
|
using namespace jni;
|
||||||
|
|
||||||
// TODO: Remove when fbjni 0.2.3 releases.
|
// TODO: Remove when fbjni 0.2.3 releases.
|
||||||
struct JArrayList : public JavaClass<JArrayList> {
|
template <typename E = jobject>
|
||||||
static constexpr auto kJavaDescriptor = "Ljava/util/ArrayList;";
|
struct JArrayList : JavaClass<JArrayList<E>, JList<E>> {
|
||||||
|
constexpr static auto kJavaDescriptor = "Ljava/util/ArrayList;";
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Marc Rousavy on 24.06.21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
#include <fbjni/fbjni.h>
|
|
||||||
|
|
||||||
namespace vision {
|
|
||||||
|
|
||||||
using namespace facebook;
|
|
||||||
using namespace jni;
|
|
||||||
|
|
||||||
struct JReadableArray : public JavaClass<JReadableArray> {
|
|
||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/ReadableArray;";
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace vision
|
|
@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Marc Rousavy on 24.06.21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
#include <fbjni/fbjni.h>
|
|
||||||
|
|
||||||
namespace vision {
|
|
||||||
|
|
||||||
using namespace facebook;
|
|
||||||
using namespace jni;
|
|
||||||
|
|
||||||
struct JReadableMap : public JavaClass<JReadableMap> {
|
|
||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/ReadableMap;";
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace vision
|
|
@ -39,8 +39,8 @@ Similar to a TurboModule, the Frame Processor Plugin Registry API automatically
|
|||||||
| `number` | `NSNumber*` (double) | `Double` |
|
| `number` | `NSNumber*` (double) | `Double` |
|
||||||
| `boolean` | `NSNumber*` (boolean) | `Boolean` |
|
| `boolean` | `NSNumber*` (boolean) | `Boolean` |
|
||||||
| `string` | `NSString*` | `String` |
|
| `string` | `NSString*` | `String` |
|
||||||
| `[]` | `NSArray*` | `ReadableNativeArray` |
|
| `[]` | `NSArray*` | `ArrayList<E>` |
|
||||||
| `{}` | `NSDictionary*` | `ReadableNativeMap` |
|
| `{}` | `NSDictionary*` | `HashMap<K, V>` |
|
||||||
| `undefined` / `null` | `nil` | `null` |
|
| `undefined` / `null` | `nil` | `null` |
|
||||||
| `(any, any) => void` | [`RCTResponseSenderBlock`][4] | `(Object, Object) -> void` |
|
| `(any, any) => void` | [`RCTResponseSenderBlock`][4] | `(Object, Object) -> void` |
|
||||||
| [`Frame`][1] | [`Frame*`][2] | [`ImageProxy`][3] |
|
| [`Frame`][1] | [`Frame*`][2] | [`ImageProxy`][3] |
|
||||||
|
Loading…
Reference in New Issue
Block a user