41 static const std::unique_ptr<LogEntryWriter> log_writer(
45 jclass clazz = env->FindClass(class_name);
46 jthrowable mException = env->ExceptionOccurred();
48 env->ExceptionDescribe();
49 env->ExceptionClear();
50 log_writer->Write(
ERROR,
51 std::string(
"Android JNI: Class ").
52 append(class_name).append(
" not found.").c_str());
56 log_writer->Write(
ERROR,
57 std::string(
"Android JNI: Class ").
58 append(class_name).append(
" not found.").c_str());
61 jclass global_clazz =
static_cast<jclass
>(env->NewGlobalRef(clazz));
62 env->DeleteLocalRef(clazz);
67 const char*
name,
const char* signature) {
68 jmethodID method = env->GetStaticMethodID(clazz, name, signature);
69 if (env->ExceptionCheck() || !method) {
70 log_writer->Write(
ERROR,
71 std::string(
"Android JNI: static method ").
72 append(name).append(
" not found in class.").
73 append(class_name).c_str());
74 env->ExceptionClear();
80 jmethodID
GetMethod(JNIEnv* env, jclass clazz,
const char* class_name,
81 const char*
name,
const char* signature) {
82 jmethodID method = env->GetMethodID(clazz, name, signature);
83 if (env->ExceptionCheck() || !method) {
84 log_writer->Write(
ERROR,
85 std::string(
"Android JNI: method ").
86 append(name).append(
" not found in class ").
87 append(class_name).c_str());
88 env->ExceptionClear();
95 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
96 return GetStaticMember(env, clazz, class_name, name,
"Ljava/lang/String;");
100 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
105 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
110 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
115 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
116 return GetMember(env, clazz, class_name, name,
"I");
120 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
121 return GetMember(env, clazz, class_name, name,
"J");
125 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
126 return GetMember(env, clazz, class_name, name,
"Z");
130 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
131 return GetMember(env, clazz, class_name, name,
"Ljava/lang/String;");
135 JNIEnv* env, jclass clazz,
const char* class_name,
const char*
name) {
136 return GetMember(env, clazz, class_name, name,
"[I");
140 const char*
name,
const char*
type) {
141 jfieldID field = env->GetStaticFieldID(clazz, name, type);
142 if (env->ExceptionCheck() || !field) {
143 log_writer->Write(
ERROR,
144 std::string(
"Android JNI: static field ").
145 append(name).append(
" not found in class ").
146 append(class_name).c_str());
147 env->ExceptionClear();
153 jfieldID
GetMember(JNIEnv* env, jclass clazz,
const char* class_name,
154 const char*
name,
const char*
type) {
155 jfieldID field = env->GetFieldID(clazz, name, type);
156 if (env->ExceptionCheck() || !field) {
157 log_writer->Write(
ERROR,
158 std::string(
"Android JNI: field ").
159 append(name).append(
" not found in class ").
160 append(class_name).c_str());
161 env->ExceptionClear();
168 return env->NewObjectArray(length, env->FindClass(
"java/lang/String"),
169 env->NewStringUTF(
""));
173 return env->NewStringUTF(s.c_str());
177 return JavaByteArray(env, reinterpret_cast<const jbyte*>(bytes.c_str()),
178 static_cast<jsize>(bytes.size()));
185 jbyteArray j_array = env->NewByteArray(size);
186 env->SetByteArrayRegion(j_array, 0, size, data);
191 jsize first, jsize size,
char* out) {
197 log_writer->Write(
ERROR,
198 "Android JNI: JavaGetByteArray called without a valid out.");
202 env->GetByteArrayRegion(array, first, size,
203 reinterpret_cast<jbyte*>(out));
207 jint result = env_->PushLocalFrame(0);
208 if (result != JNI_OK) {
209 log_writer->Write(
ERROR,
210 "Android JNI: Error on PushLocalFrame");
215 env_->PopLocalFrame(NULL);
void JavaGetByteArray(JNIEnv *env, jbyteArray array, jsize first, jsize size, char *out)
jfieldID GetStaticStringMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jbyteArray JavaByteArray(JNIEnv *env, const std::string &bytes)
void SetJVM(JavaVM *jvm)
Set the pointer to the JavaVM.
jfieldID GetStaticLongMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jfieldID GetStringMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jfieldID GetIntMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jclass FindClassGlobal(JNIEnv *env, const char *class_name)
jmethodID GetStaticMethod(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *signature)
LocalFrame(JNIEnv *env)
Pushes a local reference frame frame with env->PushLocalFrame(0).
jstring JavaString(JNIEnv *env, const std::string &s)
jfieldID GetStaticBooleanMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jfieldID GetMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *type)
jobjectArray JavaStringArray(JNIEnv *env, int length)
jfieldID GetLongMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jmethodID GetMethod(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *signature)
jfieldID GetStaticMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *type)
jfieldID GetBooleanMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
jfieldID GetStaticIntMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
ION_API LogEntryWriter * CreateDefaultLogEntryWriter()
Instantiate a new LogEntryWriter of the default type for the current platform...
jfieldID GetIntArrayMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
~LocalFrame()
Pops a local reference frame with env->PopLocalFrame(NULL);.