4

I get several errors when I try to call the class UiLifecycleHelper in a plugin between Eclipse and Unity. I copied the facebooksdk.jar in the libs folder of my project, then added it in

  • Properties > Java Build Path > Add JAR

I also tried to simply add the "library" in :

  • Properties > Android, with the button Add...

There are no errors when I don't use the class UiLifecycleHelper (the Log.i works fine from testFunc without the class UiLifecycleHelper) And without the connection with Unity, with a simple class extending Activity, it connects well to Facebook.

I also set the Java Compiler to 1.6 as recommended in other topics. Would you know how to correctly make the connection between the facebook .jar and my project?

Here are the logs :

01-05 17:17:53.834: E/dalvikvm(25005): Could not find class 'com.project.aef.MainActivity$1', referenced from method com.project.aef.MainActivity.<init>
01-05 17:17:53.835: E/dalvikvm(25005): Could not find class 'com.facebook.UiLifecycleHelper', referenced from method com.project.aef.MainActivity.onCreate
01-05 17:17:53.841: E/AndroidRuntime(25005): FATAL EXCEPTION: main
01-05 17:17:53.841: E/AndroidRuntime(25005): java.lang.NoClassDefFoundError: com.project.aef.MainActivity$1
01-05 17:17:53.841: E/AndroidRuntime(25005):    at com.project.aef.MainActivity.<init>(MainActivity.java:24)
01-05 17:17:53.841: E/AndroidRuntime(25005):    at java.lang.Class.newInstanceImpl(Native Method)
01-05 17:17:53.841: E/AndroidRuntime(25005):    at java.lang.Class.newInstance(Class.java:1319)
01-05 17:17:53.841: E/AndroidRuntime(25005):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)

EDIT : I had a similar issue with Twitter, I finally changed the code to use Activities instead of the current code, I don't know why the code works fine outside the software, and not when I connect to it. I also used Libgdx to make the game, instead of Unity. Problem solved.

Paul
  • 6,108
  • 14
  • 72
  • 128

1 Answers1

5

Your problem is with startActivity. You have to set it properly. Here is an example:

public class MyActivity extends Activity {
 ...

 static final int PICK_CONTACT_REQUEST = 0;

 protected boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
         // When the user center presses, let them pick a contact.
         startActivityForResult(
             new Intent(Intent.ACTION_PICK,
             new Uri("content://contacts")),
             PICK_CONTACT_REQUEST);
        return true;
     }
     return false;
 }

 protected void onActivityResult(int requestCode, int resultCode,
         Intent data) {
     if (requestCode == PICK_CONTACT_REQUEST) {
         if (resultCode == RESULT_OK) {
             // A contact was picked.  Here we will just display it
             // to the user.
             startActivity(new Intent(Intent.ACTION_VIEW, data));
         }
     }
 }
}

As you can see, your code is missing "Intent". That's why you have this error.

Community
  • 1
  • 1
Tanya Kadam
  • 129
  • 4
  • Thanks for the answer, are you sure in this example? The code with UILifecycleHelper is given in the sample example from the facebook SDK folder for Android and `UILifecycleHelper` does not extend `Activity`. – Paul Jan 05 '14 at 18:04
  • 1
    what I mentioned is that your code is missing "Intent". you have to include "Intent" otherwise the error will remain. as you can check here - "Intent" is needed also to use Facebook with Android: http://stackoverflow.com/questions/16403566/implementing-facebook-login-with-uilifecyclehelper – Tanya Kadam Jan 05 '14 at 18:20
  • sorry maybe I misunderstand what you are saying. Where exactly would you recommend to add the Intent? With `activity.Call("testFunc");` ? I took the code from the bottom of the page here : http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html where the activity is called with a `Call` method. – Paul Jan 05 '14 at 18:45
  • @Paul - have a look in this tutorial to start understanding "Intent": http://www.vogella.com/tutorials/AndroidIntent/article.html . – Tanya Kadam Jan 07 '14 at 12:02
  • @Paul - here some quick info about "Intent": (1) http://stackoverflow.com/questions/6578051/what-is-intent-in-android ; (2) http://stackoverflow.com/questions/6646492/what-is-the-exact-difference-between-intent-and-pending-intent/6646611#6646611 for the case you don't have the time to go through that tutorial and do the exercises. – Tanya Kadam Jan 07 '14 at 12:09
  • Thanks Tanya, I can see you are helping me and I appreciate it. But you don't explain me where in my code the problem is, so I am confused. I have used Intents many times in other applications, I know what it is in an application. With Facebook though, UILifecyleHelper is called differently, and about the call to the MainActivity class, it works without UILifecycleHelper. So without an Intent. Because it is how the documentation in Unity explains the way to go. If you are right, and you pointed out the right issue, could you be more specific and show me an example, or the line to change? – Paul Jan 08 '14 at 01:54