Android Java Libraries in UE4 Game (OUYA SDK, Google Play Game Services, etc.)

Hi tgaupmann,

The Android Plugin Language is the proper way to do what you are trying to do here. The GameActivity.java can be patched by the plugin and copying of dependencies (assets, libs, jars) can be done with it on a conditional basis. Also, there is no need to hook into JNI_OnLoad. Here is an example from earlier GearVR.cpp:


// call out to JNI to see if the application was packaged for GearVR
bool AndroidThunkCpp_IsGearVRApplication()
{
	bool bIsGearVRApplication = false;
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		static jmethodID Method = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_IsGearVRApplication", "()Z", false);
		bIsGearVRApplication = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, Method);
	}
	return bIsGearVRApplication;
}

In your OuyaSDKPlugin.Build.cs you will want to add:


			if (Target.Platform == UnrealTargetPlatform.Android)
			{
				string PluginPath = Utils.MakePathRelativeTo(ModuleDirectory, BuildConfiguration.RelativeEnginePath);
				AdditionalPropertiesForReceipt.Add(new ReceiptProperty("AndroidPlugin", Path.Combine(PluginPath, "OuyaSDKPlugin_APL.xml")));
			}

Then you can make an OuyaSDKPlugin_APL.xml in the same directory as the OuyaSDKPlugin.Build.cs. Look at GearVR_APL.xml in Engine/Plugin/Runtime/GearVR/Source/GearVR for an example. The top comment block in AndroidPluginLanguage.cs documents the XML-based language.

As for the loading issue, try adding Android to the white-list in the .uplugin (take a look at GearVR.uplugin).