Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 230
KaHeL Avatar asked Jun 18 '13 03:06

KaHeL


People also ask

Do I need the Facebook SDK?

Can I run mobile app ads without using the SDK? Yes, we allow anyone to run mobile app install ads from our Ads Create Tool simply by dropping the link to their Apple App Store or Google Play URL. For mobile app engagement ads, you will need to register your app, but can also run ads without the SDK.


2 Answers

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.
like image 147
KaHa6uc Avatar answered Oct 09 '22 12:10

KaHa6uc


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.

like image 5
Prashant Sridharan Avatar answered Oct 09 '22 14:10

Prashant Sridharan