by Anonymous » 09 Mar 2025, 10:37
Ich habe eine Android -App (in Kotlin geschrieben), wobei der Verarbeitungscode in Rost ausgeführt wird. Ich versuche, Liste Daten an das Back-End-Rust zu senden und sie als VEC zu interpretieren. Die Größe der Liste ist variabel. Ich verwende dafür JNI (Java Native Interface).
Code: Select all
package eu.mypackage.rust
class SomeName {
@Throws(IllegalArgumentException::class)
external fun checkAnswer(answerInput: String, answerList: List): Boolean
}
< /code>
mit der ich aufrufe: < /p>
val isCorrect = sn.checkAnswer(answerInput, answerList)
< /code>
rost < /h3>
Auf der Rostseite habe ich diese Entwurfsfunktion: < /p>
#[cfg(target_os = "android")]
#[allow(non_snake_case)]
pub mod android {
extern crate jni;
// This is the interface to the JVM that we'll call the majority of our methods on.
// @See https://docs.rs/jni/latest/jni/
use self::jni::JNIEnv;
// These objects are what you should use as arguments to your native function.
// They carry extra lifetime information to prevent them escaping this context
// and getting used after being GC'd.
use self::jni::objects::{JClass, JString, JObject, JObjectArray}; // Not sure what is required
// This is just a pointer. We'll be returning it from our function.
// We can't return one of the objects with lifetime information
// because the lifetime checker won't let us.
use self::jni::sys::{jstring, jboolean, jobjectArray, jsize}; // Not sure what is required
fn kotlin_list_to_rust_vec_string(env: &JNIEnv, java_array: &jobjectArray) -> Vec {
// TODO function to convert
}
#[no_mangle] // This keeps Rust from "mangling" the name so it is unique (crate).
pub extern "system" fn Java_eu_surafusoft_rust_KanjiOrigin_checkAnswer,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static native method.
_class: JClass,
answerList: JObjectArray
Ich habe eine Android -App (in Kotlin geschrieben), wobei der Verarbeitungscode in Rost ausgeführt wird. Ich versuche, Liste Daten an das Back-End-Rust zu senden und sie als VEC zu interpretieren. Die Größe der Liste ist variabel. Ich verwende dafür JNI (Java Native Interface).[code]package eu.mypackage.rust
class SomeName {
@Throws(IllegalArgumentException::class)
external fun checkAnswer(answerInput: String, answerList: List): Boolean
}
< /code>
mit der ich aufrufe: < /p>
val isCorrect = sn.checkAnswer(answerInput, answerList)
< /code>
rost < /h3>
Auf der Rostseite habe ich diese Entwurfsfunktion: < /p>
#[cfg(target_os = "android")]
#[allow(non_snake_case)]
pub mod android {
extern crate jni;
// This is the interface to the JVM that we'll call the majority of our methods on.
// @See https://docs.rs/jni/latest/jni/
use self::jni::JNIEnv;
// These objects are what you should use as arguments to your native function.
// They carry extra lifetime information to prevent them escaping this context
// and getting used after being GC'd.
use self::jni::objects::{JClass, JString, JObject, JObjectArray}; // Not sure what is required
// This is just a pointer. We'll be returning it from our function.
// We can't return one of the objects with lifetime information
// because the lifetime checker won't let us.
use self::jni::sys::{jstring, jboolean, jobjectArray, jsize}; // Not sure what is required
fn kotlin_list_to_rust_vec_string(env: &JNIEnv, java_array: &jobjectArray) -> Vec {
// TODO function to convert
}
#[no_mangle] // This keeps Rust from "mangling" the name so it is unique (crate).
pub extern "system" fn Java_eu_surafusoft_rust_KanjiOrigin_checkAnswer,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static native method.
_class: JClass,
answerList: JObjectArray