Use specialized logic when loading C modules in Android.

This commit is contained in:
Miku AuahDark
2021-11-02 17:54:13 +08:00
parent e27a71f798
commit b79b99bbaa
3 changed files with 69 additions and 0 deletions
+42
View File
@@ -724,6 +724,48 @@ bool checkFusedGame(void **physfsIO_Out)
return false;
}
const char *getCRequirePath()
{
static bool initialized = false;
static const char *path = nullptr;
if (!initialized)
{
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
jobject activity = (jobject) SDL_AndroidGetActivity();
jclass clazz(env->GetObjectClass(activity));
jmethodID method_id = env->GetMethodID(clazz, "getCRequirePath", "()Ljava/lang/String;");
path = "";
initialized = true;
if (method_id)
{
jstring cpath = (jstring) env->CallObjectMethod(activity, method_id);
const char *utf = env->GetStringUTFChars(cpath, nullptr);
if (utf)
{
path = SDL_strdup(utf);
env->ReleaseStringUTFChars(cpath, utf);
}
env->DeleteLocalRef(cpath);
}
else
{
// NoSuchMethodException is thrown in case methodID is null
env->ExceptionClear();
return "";
}
env->DeleteLocalRef(activity);
env->DeleteLocalRef(clazz);
}
return path;
}
} // android
} // love