Android: Expose asset prefix path to Java via JNI

This commit is contained in:
Michał Janiszewski
2026-03-22 17:44:40 +01:00
parent bc6bfb6329
commit ea50129130
2 changed files with 34 additions and 0 deletions
@@ -0,0 +1,24 @@
package io.openrct2;
/**
* Platform constants exposed from C++ via JNI.
* These constants are defined in the native code and exposed to Java to ensure
* the same definitions are used in both languages.
*/
public class PlatformConstants {
static {
System.loadLibrary("openrct2");
}
/**
* Android asset path prefix.
* This constant is retrieved from the native C++ code to ensure consistency.
*/
public static final String ANDROID_ASSET_PATH_PREFIX = getAndroidAssetPathPrefix();
/**
* Native method to get the Android asset path prefix from C++.
* Defined in src/openrct2/platform/Platform.Android.cpp
*/
private static native String getAndroidAssetPathPrefix();
}
@@ -487,6 +487,16 @@ namespace OpenRCT2::Platform
}
} // namespace OpenRCT2::Platform
/**
* JNI function to expose the Android asset path prefix constant to Java.
* Called from io.openrct2.PlatformConstants.getAndroidAssetPathPrefix()
*/
extern "C" JNIEXPORT jstring JNICALL
Java_io_openrct2_PlatformConstants_getAndroidAssetPathPrefix(JNIEnv* env, jclass /* clazz */)
{
return env->NewStringUTF(std::string(OpenRCT2::Platform::kAndroidAssetPathPrefix).c_str());
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved)
{
// Due to an issue where JNI_OnLoad could be called multiple times, we need