10

I have just downloaded the facebook SDK from http://github.com/facebook/facebook-android-sdk I unpack it from git and opened Eclipse. I then created a new project using existing source and selected the facebook directory. So the sdk project came up correctly (i think). Then I created a new project again using existing source and selected the "Simple" example. Its came up with errors. I went in the properties and selected Build Path section and added the facebook SDK project and applyed. All the errors disappear. I then tried to run the Example but im getting an exception on the first call to facebook SDK function ! Exception is NoClassDefFoundError. Its seems that at runtime it cannot find the class of the SDK. How come ? Any suggestions ? Someone did sucessfully run this example ? Any help would be greatly appreciated.

Fabien
  • 1,967
  • 8
  • 30
  • 42
  • 1
    for now, i found the only solution to integrate totally the sdk classes in my project. that is not so nice. – Fabien Aug 25 '10 at 09:46
  • 1
    I am using android studio. I just add the facebook sdk in my build gradle file. How to resolve this error in android studio? – Kaveesh Kanwal May 23 '15 at 12:07

10 Answers10

22

Right click on the Project. Choose Properties -> Android. Under Library click on the Add... button and select the path to the Facebook SDK Project.

Dumitru Hristov
  • 1,359
  • 1
  • 11
  • 29
12

I had your same problem, and there was a suggestion in another question thread to export the Android Facebook SDK as a jar file and add that file to your project.

Although some people said that the previous solution worked with them, it didn't work with me!

The only thing worked with me is: coping the Android Facebook SDK six classes into my project and that solved my problem.

Steps:

1- I simply copied the following 6 classes from the Android SDK into my project AsyncFacebookRunner.java DialogError.java Facebook.java FacebookError.java FbDialog.java Util.java

2- I've also copied the facebook_icon.png file from the drawable folders to my drawable folders.

3- I imported my R.java class in the the copied FbDialog.java class.

My advice is to try the jar solution first (as it is the neat way to be a developer), if it didn't work with you, then try my solution (as it is a way to solve the problem).

Thanks and hopefully it will solve your problem.

Mohamed.

Mohamed A.Karim
  • 404
  • 4
  • 13
  • I was able to export the Jar file, but I had issues where it was complaining about duplicate AndroidManifest.xml files. I manged to just export the entire jar (including resources) but deselected the AndroidManifest while creating the jar for com_facebook_android. Hope this helps someone. – Chrispix Nov 28 '11 at 04:54
  • 1
    Your solution is good! The problem is I have an irrelevant package in my project "com.facebook.android". It looks weird. – emeraldhieu Jul 11 '12 at 12:47
3

I managed to overcome this error by doing a clean build for both my project and facebook library (referenced) project.

The steps:

On Eclipse:

1) Select Project -> Clean
2) Select both your project and facebook sdk project
3) select OK
dangel
  • 1,506
  • 15
  • 10
  • This is the right way to go. I solved this by cleaning the facebook sdk project. My project regenerated com.facebook.android.R and everything went well. Avoid copying files directly in your project as this will make it harder to update when you need to. – Raphaël Agneau de Selve Dec 03 '12 at 12:58
3

I too faced the same problem. I was able to overcome this issue by placing the Facebook SDK library as well as my project(to which I want to link the Facebook SDK) within the same workspace. Now go to your project->right click->properties->android->scoll down->add->select the path to facebook SDK->press ok.

This way you can link the Facebook SDK to your project. Only adding the Facebook jar will result in an exception as this does not contain all the classes.

user_15
  • 31
  • 2
0

I also had this exception and tried almost everything i found. But then i copied the facebook sdk project to my workspace folder and then referenced it from there in my project and it worked.

Don't know why this happened, this made no sense to me as i was providing it the path while adding reference but anyways, It solved the problem.

Khurram
  • 853
  • 9
  • 15
0

I had this same problem. I solved it just by following these steps:

  1. Remove all the sample projects and the Facebook SDK from Eclipse
  2. Import the SDK and sample projects again, but this time, using the "Copy projects into workspace" option checked.
  3. Rebuild the SDK and the sample projects
  4. Working!
0

Try to mark the check-boxes in Properties -> Java Build Path -> Order and Export.

I had the same problem with the UiLifecycleHelper, and checkig both the Android Dependencies and the android-support-v4.jar worked perfectly. Better to run a clean after that.

5agado
  • 2,444
  • 2
  • 21
  • 30
0

I had similar problems. I am building one my lib project (with activities) and my main project using this lib. I had these problems. I had added the lib under the Project properties/Android section and at the bottom, as suggested correctly before, but this wasn't enough (note that both projects were compiling good). I had to change the lib project and use the full path to the layout as:

setContentView(com.example.mylib.R.layout.activity_main1);

Note that using just R.layout wasn't enough, although I have defined the:

import com.example.mylib.R;

Valid alternative is however:

import com.example.mylib.R.layout;
setContentView(layout.activity_main1);

Using Eclipse.

hth to someone

Čikić Nenad
  • 392
  • 5
  • 13
0

download bolts-android1.1.2 and put into \libs folder. then open the project properties-> java Build Path-> Project tab , Add Facebook SDK. (Facebook SDK libs must be attached with project)

Vrajesh
  • 1,312
  • 19
  • 25
-1

The new facebook SDK already had android.support.V4.jar.

And when you create a new android application, even that contains one.

Hence when you check the console, you get error message called JAR mismatch.

In that case select properties of android project -> Java Build path ->

Select Library tab -> Remove android.support.V4.jar Select Order and Export and uncheck -> Reference libraries (android.support.V4.jar)

This will fix the issue.

user1555123
  • 377
  • 3
  • 4