Remarque appeler ** Java ** à partir de ** C ++ ** dans ** l'application OpenGL ES (Android, iOS) ** de ** Visual Studio 2017 **
auto env = state->activity->env;
auto vm = state->activity->vm;
vm->AttachCurrentThread(&env, NULL);
jstring str = env->NewStringUTF("abc");
jclass cls = env->FindClass("java/lang/String");
jmethodID mid = env->GetMethodID(cls, "toCharArray", "()[C");
jcharArray ary = (jcharArray)env->CallObjectMethod(str, mid);
vm->DetachCurrentThread();
Test.java
package com.test;
public class Test
{
public boolean test()
{
return true;
}
}
AndroidManifest.xml
<application android:label="@string/app_name" android:hasCode="true">
https://stackoverflow.com/questions/14586821/android-flurry-integration-with-ndk-app http://archive.is/QzA8#selection-471.0-507.81
auto env = state->activity->env;
auto vm = state->activity->vm;
vm->AttachCurrentThread(&env, NULL);
jclass activityClass = env->FindClass("android/app/NativeActivity");
jmethodID getClassLoader = env->GetMethodID(activityClass,"getClassLoader", "()Ljava/lang/ClassLoader;");
jobject classLoaderInstance = env->CallObjectMethod(state->activity->clazz, getClassLoader);
jclass classLoader = env->FindClass("java/lang/ClassLoader");
jmethodID findClass = env->GetMethodID(classLoader, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
jstring strClassName = env->NewStringUTF("com/test/Test");
jclass classIWant = (jclass)env->CallObjectMethod(classLoaderInstance, findClass, strClassName);
jmethodID testMethod = env->GetStaticMethodID(classIWant, "test", "()Z");
jboolean retValue = env->CallStaticBooleanMethod(classIWant, testMethod);
vm->DetachCurrentThread();
Recommended Posts