Hi all,
I’m trying to modify a sample app from the Google Cardboard SDK (for VR development)
Using Unity 4.6 and Android Studio / Eclipse
My goal is to make modifications, or for this matter a simple log on different events of the app life cycle (i.e OnCreate(), OnPause() ect.).
In the exported project from Unity I find in the src directory the following file com.company.app.UnityPlayerNativeActivity
This file has all the application lifecycle methods and the basic calls which load the Unity project.
This is part of the code, as you can see, this is where I want to make the log statements:
public class UnityPlayerNativeActivity extends NativeActivity
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Setup activity layout
@Override protected void onCreate (Bundle savedInstanceState)
{
Log.d("Hello","World"); // my try to log something
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
// Quit Unity
@Override protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// Pause Unity
@Override protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
The thing is that the project manifest is pointing to a different location,
<activity android:name="com.google.vrtoolkit.cardboard.plugins.unity.UnityCardboardActivity" >
I have noticed that in the Unity project, the Cardboard SDK has a Assets/Plugins/Android
UnityCardboardActivity jar file. I believe this is the file which is called by the Manifest. As it’s the only file in the project with this name.
If I change the manifest to point to the src file com.company.app.UnityPlayerNativeActivity,
<activity android:name="com.company.app.UnityPlayerNativeActivity" >
the code will run and I will be able to log, but the Android app will crash once trying to load the Unity project with the following error:
5828/com.company.app I/Unity﹕ Exception: JNI: Init’d AndroidJavaObject with null ptr!
at UnityEngine.AndroidJavaObject…ctor (IntPtr jobject) [0x00000] in :0
at UnityEngine.AndroidJavaObject.AndroidJavaObjectDeleteLocalRef (IntPtr jobject) [0x00000] in :0
at UnityEngine.AndroidJavaObject._CallStatic[AndroidJavaObject] (System.String methodName, System.Object[ ] args) [0x00000] in :0
at UnityEngine.AndroidJavaObject.CallStatic[AndroidJavaObject] (System.String methodName, System.Object[ ] args) [0x00000] in :0
at Cardboard.ConnectToActivity () [0x00000] in :0
at Cardboard.Awake () [0x00000] in :0
(Filename: Line: -1)
Any help would be appreciated,
Thanks in advance.