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

11,784

Solution 1

It does indeed have to do with Gradle structure. Effectively, you need to create Gradle build files for the Facebook SDK. We wrote up a doc that may be able to help you. Give it a shot and be sure to provide us feedback with anything you found ambiguous or difficult, and I will look into it and modify the doc accordingly.

Keep in mind that Android Studio is in its early stages as of this writing, so it's possible that as the project progresses we may need to make changes in the doc accordingly.

I also found that sometimes I just had to shut Android Studio down and restart it before things would magically start working again.

Solution 2

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.
Share:
11,784

Related videos on Youtube

KaHeL
Author by

KaHeL

Updated on September 15, 2022

Comments

  • KaHeL
    KaHeL over 1 year

    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.

    • Taimur Khan
      Taimur Khan over 8 years
      I have done so in android studio v1.5, Gradle v2.8, android plugin v1.5.0 by -> go to File-> Project Structure -> go to app under module section->dependencies ->click on + icon and select library dependency->search for facebook sdk and it will provide you a list of facebook sdk including old and latest one by facebook like sdk: 4.8.2 -> select the required sdk and it will be downloaded and also imported into your dependency.
  • KaHeL
    KaHeL almost 11 years
    A big thumbs up for you guys. Thanks a lot! :)
  • KaHeL
    KaHeL almost 11 years
    hi. I tried to do the steps stated on the document you have given but it's still weird cause I get an error even though I follow the steps thoroughly. See my question here: stackoverflow.com/questions/17463154/… Hope you can help me once again regarding this. Thanks! :)
  • QuangDT
    QuangDT over 10 years
    @Prashant Those instructions have been out of date for more than 1 month. It would really be helpful if someone could advise how to install the sdk on the latest version of android studio
  • Philip
    Philip over 10 years
    @RunLoop you could use this project. The whole Facebook SDK has been gradlelized and even 3.6.0 is being supported now. github.com/mente/facebook-api-android-aar
  • Aracem
    Aracem about 10 years
    Why do you not publish your Facebook sdk like everybody? Publish it on mavencentral or on your own maven repository. That make all more easy...