Hello Readers,
In today's post we will learn to import Android Facebook SDK in eclipse. We faced several problems when import Facebook SDK in eclipse. To import we need to follow the steps as mentioned below:
- First of all, we need to download latest Facebook SDK- Click here. After download now unzip it in a folder.
- Now open eclipse and import the project. Right click on Package explorer > select import. Then a window will appear and click on Android > select Existing Android Code Into Workspace. Now click on browse and select the folder where you unzip the Facebook SDK.
Note: Select only Facebook project and unchecked all other projects we do not need them as they are sample projects.
Importing the project :
![](http://findnerd.s3.amazonaws.com/imagedata/6320/6320.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6319/6319.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6321/6321.png)
- After add Facebook project in eclipse we will see there are lots of error in the whole project.
![](http://findnerd.s3.amazonaws.com/imagedata/6322/6322.png)
- In the project we will see most of the errors occur due to SDK tried to import support.v4 library. You can find support.v4 library in ADT bundle of eclipse > sdk > extras > android > support > v4.
- Now we have to add the support.v4 library in Facebook SDK project. To add the library right click on the project > Properties > Java Build Path > Libraries > Add External Jars and goto the folder where is the support library stored.
![](http://findnerd.s3.amazonaws.com/imagedata/6323/6323.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6324/6324.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6325/6325.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6326/6326.png)
- Now we can see most of the errors were fixed after adding the library. Now will move to the other errors. In AccessToken.java file we find an error when we move the mouse pointer on it eclipse shows the hint on the error i.e the '<>' operator is not allowed for source level below 1.7. It will show two fixes for the error we can fix the error by click on Change project compliance and JRE to 1.7 or we can fix it manually right click on the project and select Properties > Java Compiler > Compiler compliance level > 1.7 .
We can fix the error by click on Change project compliance and JRE to 1.7 :
![](http://findnerd.s3.amazonaws.com/imagedata/6328/6328.png)
Or we can fix it manually change the compliance level from 1.6 to 1.7 in Java Compiler section.
will![](http://findnerd.s3.amazonaws.com/imagedata/6323/6323.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6329/6329.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6330/6330.png)
- Now we are facing another error i.e Facebook SDK can't find required Bolts Android library. Now we need to add the required Bolts Android library we can search on Google or click here for download. In my project, I am using bolts-android-1.1.2 version. After downloading the library now add it to the project right click on project > Properties > Java Build Path > Libraries > Add External Jars and add the library from you save the file.
![](http://findnerd.s3.amazonaws.com/imagedata/6331/6331.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6323/6323.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6326/6326.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6333/6333.png)
![](http://findnerd.s3.amazonaws.com/imagedata/6332/6332.png)
- After complete all above steps, you will see all of the errors are gone.
- Do not forget to final setup in the Facebook Project. Right click on project click on Properties > Android > select Is Library.
![](http://findnerd.s3.amazonaws.com/imagedata/6334/6334.png)
- Now clean the whole project so that all files can build properly.
This is the easiest way to import Facebook SDK in eclipse and we can add the Facebook library in our Android app.
Hope this will help you :)
0 Comment(s)