extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_NativeExports_loadLibraries(JNIEnv* env, jclass cls, jstring jlibPath, jint jandroidSDK) { LOGI("Loading native libraries"); // Clear stale error messages dlerror(); // Get the library path from the java-managed string const char *libPath = env->GetStringUTFChars(jlibPath, 0); char path[256]; strcpy(path, libPath); env->ReleaseStringUTFChars(jlibPath, libPath); #ifdef __i386__ // ARM libraries are already PIC-compliant // Check if PIC libraries are needed if (jandroidSDK >= ANDROID_SDK_VERSION_M) { coreLibraryName = "mupen64plus-core-pic"; } #endif // Open shared libraries handleAEI = loadLibrary(path, "ae-imports"); handleSDL = loadLibrary(path, "SDL2"); handleFreetype = loadLibrary(path, "freetype"); handleCore = loadLibrary(path, coreLibraryName); handleFront = loadLibrary(path, "mupen64plus-ui-console"); // Make sure we don't have any typos if (!handleAEI || !handleSDL || !handleFreetype || !handleCore || !handleFront ) { LOGE("Could not load libraries: be sure the paths are correct"); } // Find and call the JNI_OnLoad functions manually since we aren't loading the libraries from Java pJNI_OnLoad JNI_OnLoad0 = (pJNI_OnLoad) locateFunction(handleAEI, "ae-imports", "JNI_OnLoad"); pJNI_OnLoad JNI_OnLoad1 = (pJNI_OnLoad) locateFunction(handleSDL, "SDL2", "JNI_OnLoad"); JNI_OnLoad0(mVm, mReserved); JNI_OnLoad1(mVm, mReserved); JNI_OnLoad0 = NULL; JNI_OnLoad1 = NULL; // Find library functions aeiInit = (pAeiInit) locateFunction(handleAEI, "ae-imports", "Android_JNI_InitImports"); sdlInit = (pSdlInit) locateFunction(handleSDL, "SDL2", "SDL_Android_Init"); sdlSetScreen = (pSdlSetScreen) locateFunction(handleSDL, "SDL2", "Android_SetScreenResolution"); sdlMainReady = (pVoidFunc) locateFunction(handleSDL, "SDL2", "SDL_SetMainReady"); coreDoCommand = (pCoreDoCommand) locateFunction(handleCore, coreLibraryName, "CoreDoCommand"); coreShutdown = (pCoreShutdown) locateFunction(handleCore, coreLibraryName, "CoreShutdown"); frontMain = (pFrontMain) locateFunction(handleFront, "mupen64plus-ui-console", "SDL_main"); nativeResume = (pNativeResume) locateFunction(handleSDL, "SDL2", "Java_org_libsdl_app_SDLActivity_nativeResume"); nativePause = (pNativePause) locateFunction(handleSDL, "SDL2", "Java_org_libsdl_app_SDLActivity_nativePause"); // Make sure we don't have any typos if (!aeiInit || !sdlInit || !sdlSetScreen || !sdlMainReady || !coreDoCommand || !frontMain || !nativeResume || !nativePause || !coreShutdown) { LOGE("Could not load library functions: be sure they are named and typedef'd correctly"); } }
extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_NativeExports_loadLibraries(JNIEnv* env, jclass cls, jstring jlibPath) { LOGI("Loading native libraries"); // Construct the library paths const char *libPath = env->GetStringUTFChars(jlibPath, 0); char pathAEI[256]; char pathSDL[256]; char pathCore[256]; char pathFront[256]; sprintf(pathAEI, "%s/libae-imports.so", libPath); sprintf(pathSDL, "%s/libSDL2.so", libPath); sprintf(pathCore, "%s/libcore.so", libPath); sprintf(pathFront, "%s/libfront-end.so", libPath); env->ReleaseStringUTFChars(jlibPath, libPath); // Open shared libraries handleAEI = dlopen(pathAEI, RTLD_NOW); handleSDL = dlopen(pathSDL, RTLD_NOW); handleCore = dlopen(pathCore, RTLD_NOW); handleFront = dlopen(pathFront, RTLD_NOW); // Make sure we don't have any typos if (!handleAEI || !handleSDL || !handleCore || !handleFront) { LOGE("Could not load libraries: be sure the paths are correct"); } // Find and call the JNI_OnLoad functions manually since we aren't loading the libraries from Java pJNI_OnLoad JNI_OnLoad0 = (pJNI_OnLoad) dlsym(handleAEI, "JNI_OnLoad"); pJNI_OnLoad JNI_OnLoad1 = (pJNI_OnLoad) dlsym(handleSDL, "JNI_OnLoad"); JNI_OnLoad0(mVm, mReserved); JNI_OnLoad1(mVm, mReserved); JNI_OnLoad0 = NULL; JNI_OnLoad1 = NULL; // Find library functions aeiInit = (pAeiInit) dlsym(handleAEI, "Android_JNI_InitImports"); sdlInit = (pSdlInit) dlsym(handleSDL, "SDL_Android_Init"); sdlSetScreen = (pSdlSetScreen) dlsym(handleSDL, "Android_SetScreenResolution"); sdlMainReady = (pVoidFunc) dlsym(handleSDL, "SDL_SetMainReady"); coreDoCommand = (pCoreDoCommand) dlsym(handleCore, "CoreDoCommand"); frontMain = (pFrontMain) dlsym(handleFront, "SDL_main"); // Make sure we don't have any typos if (!aeiInit || !sdlInit || !sdlSetScreen || !sdlMainReady || !coreDoCommand || !frontMain) { LOGE("Could not load library functions: be sure they are named and typedef'd correctly"); } }