diff --git a/distribution/changelog.txt b/distribution/changelog.txt index b20dbb7b5c..c530f1c585 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -10,6 +10,7 @@ - Fix: [#18199] Dots in the game save's name no longer get truncated. - Fix: [#19722] “Forbid tree removal” restriction doesn't forbid removal of large scenery tree items. - Fix: [#20356] Cannot set tertiary colour on small scenery. +- Fix: [#20679] Android: game crashes at launch. - Fix: [#20737] Spent money in player window underflows when getting refunds. - Fix: [#20778] [Plugin] Incorrect target api when executing custom actions. - Fix: [#20807] Tertiary colour not copied with small scenery. diff --git a/src/openrct2-android/gradle.properties b/src/openrct2-android/gradle.properties index acf164f6cd..fa2c20f971 100644 --- a/src/openrct2-android/gradle.properties +++ b/src/openrct2-android/gradle.properties @@ -18,3 +18,4 @@ # org.gradle.parallel=true android.enableJetifier=true android.useAndroidX=true +org.gradle.jvmargs=-Xmx4096m diff --git a/src/openrct2/platform/Platform.Android.cpp b/src/openrct2/platform/Platform.Android.cpp index 068432d18d..54c9350978 100644 --- a/src/openrct2/platform/Platform.Android.cpp +++ b/src/openrct2/platform/Platform.Android.cpp @@ -27,7 +27,9 @@ AndroidClassLoader::~AndroidClassLoader() jobject AndroidClassLoader::_classLoader; jmethodID AndroidClassLoader::_findClassMethod; -static std::shared_ptr acl = std::make_shared(); +// Initialized in JNI_OnLoad. Cannot be initialized here as JVM is not +// available until after JNI_OnLoad is called. +static std::shared_ptr acl; namespace Platform { @@ -181,6 +183,19 @@ namespace Platform } } // namespace Platform +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) +{ + // Due to an issue where JNI_OnLoad could be called multiple times, we need + // to make sure it is only initialized once. + // https://issuetracker.google.com/issues/220523932 + // Otherwise JVM complains about jobject-s having incorrect serial numbers. + if (!acl) + { + acl = std::make_shared(); + } + return JNI_VERSION_1_6; +} + AndroidClassLoader::AndroidClassLoader() { LOG_INFO("Obtaining JNI class loader");