Facebook SDK import into Android Studio and add it in my app

KaHeL picture KaHeL · Jun 18, 2013 · Viewed 11.8k times · Source

Hi just want to know the steps in adding the facebook SDK for Android Studio. Well I already tried doing it in eclipse but this time I'm really lost on what to do since the steps given in facebook developers page is still on eclipse (https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/)

I read some questions about this problem and I think it has something to do with the gradle stucture wherein I'm not familiar with. Which is why I'm asking for the steps on how to do this. Well basically what I just need is to incorporate a facebook login in my app and just get the ID and username. make the login persist until signed out and that's all. Thanks in advance.

Answer

KaHa6uc picture KaHa6uc · Jan 15, 2014

Here's how I managed to make Facebook SDK 3.6 work with Android Studio 0.4.2 after 2 days of battle, since this great article in Facebook Devs is based on Android Studio 0.3.0 and some important parts are not applicable in the new version.

  • Create a new Android App Project.
  • Paste the "facebook" directory from the Facebook SDK directly into the root directory of the project.
  • Modify project's settings.gradle to include ":facebook". e.g.

include ':facebook', ':helloworldapp'

  • Modify main module's (helloworldapp's) build.gradle to include facebook in dependencies. e.g.
dependencies {
    compile project(':facebook')
    compile 'com.android.support:appcompat-v7:+'
}
  • Make project, and that's it - a walk in the park! You can now import com.facebook.*, you can now add <com.facebook.widget.LoginButton /> to your layout.