Wednesday, November 5, 2014

Facebook SDK for Android

[Install the Prerequisites]
1. Prepare your Android development environment
    * Get the Android SDK: http://developer.android.com/sdk/index.html
    * Development tools: JDK 6 (JRE alone is not sufficient), Apache Ant 1.8 or later
    * Create AVD: http://developer.android.com/tools/devices/managing-avds.html
    * Adding SDK Packages: http://developer.android.com/sdk/installing/adding-packages.html
    * Building Your First App: http://developer.android.com/training/basics/firstapp/index.html

2. You'll need to have the Android 2.2 (API 8) components installed in order to use the Facebook SDK.

[Download the Facebook SDK and install Facebook APK for AVD]
1. Download them:
    https://developers.facebook.com/resources/facebook-android-sdk-current.zip
    https://developers.facebook.com/resources/Facebook-11.zip

2. Export PATH:
    * set_env_android.sh:
       $ cat set_env_android.sh
       ANDROID_SDK_HOME="/home/linst/ws/android/ws/adt-bundle-linux-x86_64-20140702/sdk";

       export PATH="${PATH}:${ANDROID_SDK_HOME}/platform-tools";
       export PATH="${PATH}:${ANDROID_SDK_HOME}/tools";

    * source it:
       $ source set_env_android.sh
       $ which adb
       /home/linst/ws/android/ws/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb
 
3. Install Facebook APK to emulator:
    * Reason:
"The Facebook SDK uses Facebook's native app to provide support for authentication when it's present. On a real device, you can test this by simply installing this app for free from Google Play. However, it's not possible to access Google Play on an emulator. If you want to test the flow there, you can download and extract the APK of the Facebook app. It should be named Facebook-11.apk or similar. To install it onto an Android emulator ... "
    * Start AVD
    * Install:
       $ unzip Facebook-11.zip
       Archive:  Facebook-11.zip
         inflating: Facebook-11.apk      

       $ adb devices
       List of devices attached
       emulator-5554 device

       $ adb install ./Facebook-11.apk
       2533 KB/s (40683138 bytes in 15.680s)
        pkg: /data/local/tmp/Facebook-11.apk
       Success

4. Import the SDK into Eclipse:
    * Unzip the Facebook SDK:
       $ unzip facebook-android-sdk-3.20.0.zip
    * Import the Facebook SDK library and the samples to Eclipse:
"The installation folder contains a directory called facebook, which is the SDK project itself. There is
also a selection of sample projects in the 
samples folder."

"To import the SDK library project and the samples, with the new SDK, go to Eclipse's 'File' > 'Import' menu, and select 'General' / 'Existing Projects into Workspace'"

"Browse to select the root of your SDK folder, facebook-android-sdk-3.16. The SDK should appear in the list as 'FacebookSDK' along with all of the samples."

"You must unselect the 'Copy projects into workspace' option so that each of the sample projects retains a correct reference to the neighboring SDK. However, this means that Eclipse creates a link to the project in the SDK installation, rather than making a copy of it."

    * Clean your projects to remove build errors: Project -> Clean... -> Clean all projects.
    * Some important paths:
       Facebook SDK root path: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0
       Facebook SDK library: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0/facebook
       Basic Samples: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0/samples
       AudienceNetwork Samples: /home/linst/ws/android/ws/facebook-android-sdk-3.20.0/AudienceNetwork

References:
https://developers.facebook.com/docs/android
https://developers.facebook.com/docs/android/getting-started/
https://developers.facebook.com/docs/reference/android/current

No comments:

Post a Comment