I’m having trouble adding java methods to UE 5.4’s Gameactivity through gameActivityClassAdditions. My APL.xml is successfully referenced through my main project’s build.cs. APL.xml contains this method isGooglePlayServicesAvailable:
<gameActivityClassAdditions>
<![CDATA[
public int isGooglePlayServicesAvailable(android.content.Context context) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
return googleApiAvailability.isGooglePlayServicesAvailable(context);
}
</gameActivityClassAdditions>
]]>
And I’m trying to call the method through JNI in the modules’ GoogleFitIntegration.cpp:
bool UGoogleFitIntegrationBPLibrary::IsGooglePlayServicesAvailable()
{
#if PLATFORM_ANDROID
if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
{
UE_LOG(LogGoogleFitIntegration, Log, TEXT("Attempting to find GameActivity class"));
jclass GameActivityClass = FAndroidApplication::FindJavaClass("com/epicgames/unreal/GameActivity");
if (GameActivityClass)
{
UE_LOG(LogGoogleFitIntegration, Log, TEXT("GameActivity class found, looking for isGooglePlayServicesAvailable method"));
jmethodID MethodID = Env->GetMethodID(GameActivityClass, "isGooglePlayServicesAvailable", "(Landroid/content/Context;)I");
if (MethodID)
{
UE_LOG(LogGoogleFitIntegration, Log, TEXT("Method found, calling isGooglePlayServicesAvailable"));
jobject ActivityContext = FAndroidApplication::GetGameActivityThis();
jint Result = Env->CallIntMethod(ActivityContext, MethodID, ActivityContext);
if (Env->ExceptionCheck())
{
UE_LOG(LogGoogleFitIntegration, Error, TEXT("Exception occurred while calling isGooglePlayServicesAvailable"));
Env->ExceptionDescribe();
Env->ExceptionClear();
return false;
}
UE_LOG(LogGoogleFitIntegration, Log, TEXT("isGooglePlayServicesAvailable returned: %d"), Result);
return (Result == 0); // ConnectionResult.SUCCESS
}
else
{
UE_LOG(LogGoogleFitIntegration, Error, TEXT("Failed to find isGooglePlayServicesAvailable method"));
}
}
else
{
UE_LOG(LogGoogleFitIntegration, Error, TEXT("Failed to find GameActivity class"));
}
}
else
{
UE_LOG(LogGoogleFitIntegration, Error, TEXT("Failed to get JNIEnv"));
}
return false;
#else
UE_LOG(LogGoogleFitIntegration, Warning, TEXT("IsGooglePlayServicesAvailable is only implemented for Android."));
return false;
#endif
}
I’ve made it blueprint callable in GoogleFitIntegration.h:
UFUNCTION(BlueprintCallable, Category = "Google Fit")
static bool IsGooglePlayServicesAvailable();
And added an “Is Google Play Services Available” node to a game mode base blueprint, after Beginplay event and an initializer node. When running the apk on an android phone, I getting the confirmation log I set in the .cpp file:
GameActivity class found, looking for isGooglePlayServicesAvailable method
However, I continue to get:
Error: Failed to find isGooglePlayServicesAvailable method
The game launches, then immediately crashes when trying to run the node. It seems like UE can’t find the java class addition I’ve added through the APL file, and I’m running out of ideas on what’s causing it. I’m open to any and all suggestions and can provide more context if needed.