C#: Don't use ActivityThread to determine Android nativeLibraryDir
This commit is contained in:
parent
ecedc7df0b
commit
690bf12c4c
1 changed files with 10 additions and 7 deletions
|
@ -109,16 +109,18 @@ bool jni_exception_check(JNIEnv *p_env) {
|
||||||
String app_native_lib_dir_cache;
|
String app_native_lib_dir_cache;
|
||||||
|
|
||||||
String determine_app_native_lib_dir() {
|
String determine_app_native_lib_dir() {
|
||||||
|
// The JNI code is the equivalent of:
|
||||||
|
//
|
||||||
|
// return godotActivity.getApplicationInfo().nativeLibraryDir;
|
||||||
|
|
||||||
JNIEnv *env = get_jni_env();
|
JNIEnv *env = get_jni_env();
|
||||||
|
|
||||||
ScopedLocalRef<jclass> activityThreadClass(env, env->FindClass("android/app/ActivityThread"));
|
GodotJavaWrapper *godot_java = static_cast<OS_Android *>(OS::get_singleton())->get_godot_java();
|
||||||
jmethodID currentActivityThread = env->GetStaticMethodID(activityThreadClass, "currentActivityThread", "()Landroid/app/ActivityThread;");
|
jobject activity = godot_java->get_activity();
|
||||||
ScopedLocalRef<jobject> activityThread(env, env->CallStaticObjectMethod(activityThreadClass, currentActivityThread));
|
|
||||||
jmethodID getApplication = env->GetMethodID(activityThreadClass, "getApplication", "()Landroid/app/Application;");
|
|
||||||
ScopedLocalRef<jobject> ctx(env, env->CallObjectMethod(activityThread, getApplication));
|
|
||||||
|
|
||||||
jmethodID getApplicationInfo = env->GetMethodID(env->GetObjectClass(ctx), "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
|
ScopedLocalRef<jclass> contextClass(env, env->FindClass("android/content/Context"));
|
||||||
ScopedLocalRef<jobject> applicationInfo(env, env->CallObjectMethod(ctx, getApplicationInfo));
|
jmethodID getApplicationInfo = env->GetMethodID(contextClass, "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
|
||||||
|
ScopedLocalRef<jobject> applicationInfo(env, env->CallObjectMethod(activity, getApplicationInfo));
|
||||||
jfieldID nativeLibraryDirField = env->GetFieldID(env->GetObjectClass(applicationInfo), "nativeLibraryDir", "Ljava/lang/String;");
|
jfieldID nativeLibraryDirField = env->GetFieldID(env->GetObjectClass(applicationInfo), "nativeLibraryDir", "Ljava/lang/String;");
|
||||||
ScopedLocalRef<jstring> nativeLibraryDir(env, (jstring)env->GetObjectField(applicationInfo, nativeLibraryDirField));
|
ScopedLocalRef<jstring> nativeLibraryDir(env, (jstring)env->GetObjectField(applicationInfo, nativeLibraryDirField));
|
||||||
|
|
||||||
|
@ -369,6 +371,7 @@ void initialize() {
|
||||||
String so_path = path::join(app_native_lib_dir, godot_so_name);
|
String so_path = path::join(app_native_lib_dir, godot_so_name);
|
||||||
|
|
||||||
godot_dl_handle = try_dlopen(so_path, gd_mono_convert_dl_flags(MONO_DL_LAZY));
|
godot_dl_handle = try_dlopen(so_path, gd_mono_convert_dl_flags(MONO_DL_LAZY));
|
||||||
|
ERR_FAIL_COND(!godot_dl_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup() {
|
void cleanup() {
|
||||||
|
|
Loading…
Reference in a new issue