49

Are there some way to import the new Facebook SDK for Android to Eclipse without Gradle or Maven (something like the past way)? I've been watching some pages but i don't find a the way.

Thanks

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Amaury Esparza
  • 1,028
  • 2
  • 12
  • 18

4 Answers4

192

I also have faced this problem, so I will write a short guide, how to install it in Eclipse.

Step 1. Import to Eclipse

First of all, download the latest version of SDK (on current moment it is 4.0). Unzip it to a folder.

Open Eclipse, click the right mouse button in "PackageExplorer" and choose "Import". After that, go to "Android" -> "Existing Android Code Into Workspace".

enter image description here

Now click "Browse" and choose unzipped SDK folder, and deselect all other found projects, except from the "facebook" (it is an SDK). Other included projects are just samples, and you don't need them now.

enter image description here

You may select "copy project to workspace" checkbox, if you need this.

Step 2. Fixing errors

After importing, we will see, that the whole facebook SDK package are in errors:

enter image description here

But if we look closer, and open one of marked as error classes, we will find, that SDK tried to importsupport.v4 library:

enter image description here

It required for properly compilation. You can find instructions how to download it using Android SDK Managerhere.

After it downloading, you can find it in your Android sdk folder: <sdk>/extras/android/support/v4. Then add it to the facebook SDK project: right mouse click on SDK project -> "Properties" -> "Java Build Path" -> "Libraries" -> "Add External JARs", and choose android-support-v4.jar from it's folder.

enter image description here enter image description here enter image description here

After that a lot of errors will be gone:

enter image description here

But, there are other errors. So we are going to another class, and found it error code piece. Move mouse pointer on it, and Eclipse will show you the hint, of what kind of error you are facing. It says that your compliance Java must be version 1.7. Allow Eclipse do it by clicking "Change project ...", or do it manually by going to "Properties" -> "Java Complier" -> "Compiler compilance level" -> "1.7".

enter image description here

OR

enter image description here

Moving ahead. Now we are facing only one kind of error, that says that the FB SDK can't find required Bolts Android library.

enter image description here

We are going to google, found it compiled jar in a repository. Choose the latest version (for current moment it's 1.2.0, but SDK gradle file is using 1.1.4, so you may choose that), and download the jar. Now add it to the facebook SDK as external lib, as we do it before.

enter image description here

Voila! Ther are no errors anymore!

enter image description here

Also don't forget to set in the facebook SDK project "Properties" -> "Android", that it is a Library.

enter image description here

Just for ensurance, close/re-open the SDK project and clean it ("Eclipse menu" -> "Project" -> "Clean"), so all files can build properly.

Step 3. Add it to the Android project

Now you can try to add it to your Android app. Go to your Android app project "Properties" -> "Android" -> "Library" -> "Add", and choose facebook SDK.

enter image description here

Follow official tutorial, and set up your Android application project (don't forget to add all required elements to Manifest.xml). Than you can use this tutorial to add LoginButton to your Activity. Try to build it. It should run without problem.

enter image description here

VadymVL
  • 5,366
  • 3
  • 26
  • 41
  • Thank you. Just had to take over a project on eclipse and the first thing the client wanted was to upgrade facebook. Super useful and well illustrated guide. Might not be the cleanest solution in regards to gradle but it is a nice temporary solution. – user1732313 Apr 03 '15 at 08:41
  • 2
    Thanks. It works very well. I spent lot of time researching on this integration as the SDK is gradle based. I did integrate it in Android Studio properly but A'Studio has no support for TFS. So back to eclipse now. – Amit Trivedi Apr 14 '15 at 05:40
  • ** Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 14 ** i still get this error :( pls help – Anitha May 18 '15 at 10:20
  • ohh sorry i got it... hadn't change android target........ now works fine... @VadymVL thanks alot... – Anitha May 18 '15 at 10:37
  • @VadymVL please take a look at http://stackoverflow.com/questions/30570800/issues-creating-login-button-using-facebook-sdk-4-1-2 – kittu88 Jun 01 '15 at 10:21
  • 3
    Well, thanks, after importing facebook sdk project, I bypassed many errors by applying those steps. However my facebook project still cannot be compiled without errors. My errors are all based upon "The import com.facebook.R cannot be resolved". There must be an error in resource files and Buildconfig.java R. java could not be generated. What can I do? edit: I found the source of error "Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 10" it says. I changed the target API to 20, the problem solved. – fercis Aug 26 '15 at 08:47
  • 7
    I tried following this guide but didnt work (for the current 4.7.0 sdk). It doesnt find the facebook project on the import (only the AudienceNetwork ones), then I tried unzipping the .aar file and then it finds a project but it has no source inside (no errors after import, but also no access to FB methods after importing library project on main project)... any ideas? EDIT: I created a libs folder on the imported FB project and copied the classes.jar there and now I can see the FB methods on my main project, but no idea if it will work or is a stable solution. Anyone?? – pertz Nov 06 '15 at 18:13
  • @rottz I haven't tested my tutorial on the latest versions of FB SDK, but AAR is just archive. How to unpack it you can find [here](http://www.iphonedroid.com/blog/en/utilizar-ficheros-aar-en-eclipse/#.Vj0KbpBxKUk). If you can see the FB methods on your main project, it means that all should works fine. – VadymVL Nov 06 '15 at 20:20
  • 2
    I have downloaded facebook sdk from github (https://github.com/facebook/facebook-android-sdk), the sub folder libs has all necessary extra libraries. Just add them as external ones. – Tony Nov 27 '15 at 06:36
  • 9
    For those who don't find facebook but only AudienceNetwork stuff when they try to import, just download the SDK 4.0 (https://developers.facebook.com/docs/android/downloads) and it will work just like in the anwser. – Gannicus Dec 02 '15 at 12:14
  • 1
    SDK 4.5 or 4.6 seems to be the last version that supports this method – Chanon Apr 20 '16 at 08:08
3

you can also use the following code it works for me, while using Facebook SDK 4.7 link

Community
  • 1
  • 1
Kushal
  • 795
  • 1
  • 5
  • 23
0

Yes you can get the downloadable SDK from this page "Getting Started" then you select your facebook app already prepared, and you click Download the Facebook SDK for Android, Unzip the package and note the location of your the folder Enjoy

  • 1
    I've already try to do it in Eclipse and doesn't work, are you already do it? Can you show some screenshots? please, thanks – Amaury Esparza Apr 01 '15 at 18:46
-7

Both of the above answers/comments are incorrect. The latest Facebook SDK ,4.0, is targeted at Android Studio and gradle.

In particular, there are no external libs included in the downloaded project. They are configured as compile dependencies in the build.gradle file.

dependencies {
compile 'com.android.support:support-v4:[21,22)'
compile 'com.parse.bolts:bolts-android:1.1.4'

}

You would need to create a libs folder in the facebook project directory and add the support-v4 and bolt-android jars to it and then add the jars to your build path.

I also encountered an issue with JDK Compliance. My projects defaults were JDK 1.6 but the Facebook library requires JDK 1.7. The solution to that was to change the settings for the facebook project under the Java -> Compile settings.

jjhorgan
  • 107
  • 1
  • 5