Last updated on July 31st, 2016 at 11:16 am
Here is a new updated tutorial About Facebook Integration and Login.
Facebook is a largest social networking website over internet. Today we have no of mobile application which ask you to login with your facebook account. To make your app facebook enable you need to integrate facebook in your android application. Integration of facebook is very easy in eclipse there are thousand of blogs which explain how to integrate facebook in eclipse project but there is very limited blog which properly explain you how to integrate facebook sdk in android studio. In this post i will explain you to integrate facebook SDK in android studio.
Android Studio 0.8.9
Integrating facebook in android studio
Now before starting integrating facebook you need some important thing to do
- Download Facebook SDK from facebook official website: https://developers.facebook.com/docs/android.
Generating App Signature for Facebook Settings
To integrate facebook into your app you need to provide your application signature. The best and simple way to generate keyhash is to use openssl. Download openSSL from here, after download unzip downloaded file.
Now open your CMD and paste command:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "F:\software\openssl-0.9.8k_WIN32\bin\openssl.exe" sha1 -binary | "F:\software\openssl-0.9.8k_WIN32\bin\openssl.exe" base64
update openssl.exe location of above cmd with your unzip file location to get your hashkey.
After writing/copy to cmd this command when your need to create a password after that you get your hashkey copy it.
Now create new facebook app login first after visit this link to create new app https://developers.facebook.com/. And after click on setting button left side of screen and paste your Key Hashes there as shown below.
Now get your AppID we need it in our program later.
Integrating facebook in android studio
Start your New Android Project
1. Create a new project in Android Studio from File ⇒ New ⇒ Android Application Project .
2. Now minimize or close your Android Studio. Go to your project directory inside it create a new folder as shown below
name your folder i name my folder libraries.
3. UnZip your facebook SDK folder, now we need to copy facebook project files to our newly created libraries folder. Open your unzip folder and find facebook folder. In my case i found here F:\socialsdk\facebook-android-sdk-3.16.0\facebook-android-sdk-3.16 i extract facebook sdk in f drive inside socialssdk. You find your where you extract sdk files.
4. Now open your copied facebook folder inside libraries and we need to remove some folder which we don’t need in our project keep files which shown image below and remove other file and folders.
5. Now open your android studio and open your project you create for this. Now find your libraries folder in your project and facebook inside
5. Open your facebook build.gradle inside facebook folder we need to configure some setting in this file update file as shown below
Libraries ⇒ facebook ⇒ build.gradle
apply plugin: 'android-library' dependencies { compile 'com.android.support:support-v4:19.1.+' compile files('libs/bolts.jar') } android { compileSdkVersion 20 buildToolsVersion "20.0.0" defaultConfig { minSdkVersion 14 targetSdkVersion 20 versionCode 1 versionName "1.0" } lintOptions { abortOnError false } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] } } }
You also copy and paste above code in your build.gradle.
6. Now open your ProjectDirectory ⇒ settings.gradle. In this file we need to include our facebook library
include ':app' include ':libraries:facebook'
if you don’t find Sync Now button at top right corner then make add some white space any where to get this and sync it.
7. Now you need to configure your project structure shortcut Ctrl+Alts+Shift+S or you can click on button as shown in image below
After click on button select Module ⇒ Dependencies ⇒ + ⇒ Module Dependencies
After this select facebook module and click ok button and then Apply and let grable sync after this your Facebook SDK is ready to use in your project.
Stay tune i make application using this integration in my post soon!.
Thank you!