Note: This guide is organized to follow after the shared setup steps for the Facebook SDK for Unity detailed in the Getting Stared guide. If you have not yet completed these steps please do so first.
This document provides an follow up step-by-step guide to get started with the Facebook SDK for Unity on Android. We will build and deploy the sample Unity app bundled with the Unity SDK to allow you to get working on a Facebook integration quickly and effectively. If you're more comfortable working on iOS or Web, you can switch to the Getting Started guides for those platforms.
Step 1: Switch to the Android Platform
Go to the Unity Editor. From the menu, choose 'File', 'Build Settings…' In the Build Settings dialog, under 'Platform', select 'Android' as the target and click 'Switch Platform'. Ensure the sample project scenes have been added to the 'Scenes in Build' as previously described here.
Step 2: Set Android Miniimum API Level
Click on Player Settings and make sure the android Minimum API level is set to "Android 4.0.3 'Ice Cream Sandwich' (API level 15)" or higher.
Step 3: Configure Bundle ID and Key Hash
With the Build Settings dialog still open, click 'Player Settings...' Then, in the Inspector pane go to 'Settings for Android', then 'Other Settings'. Fill in the 'Bundle Identifier' field with a valid bundle identifier, usually formed using your company name and product name. Save your project.
Now select 'Edit Settings' from the 'Facebook' menu.
Find and note the value of the 'Debug Android Key Hash' in the 'Android Build Facebook Settings' panel. Also note the value of the 'Class Name'.
Now, let's add the Bundle ID, Key Hash, and Class Name to your app's Facebook settings. Go to the 'Android' pane in the Basic tab of your app's 'Settings' page, and fill in the 'Bundle ID', 'Key Hashes' , and 'Class Name' fields. Now save your changes.
Step 4: Build
Now, back in the Unity Editor, click the 'Build' button. When prompted for an output directory name, call it
unity_android. You can choose to export an APK file directly, which you can install on a test device, or to export a project file to be opened in your Android IDE.
Now you're up and running on Android. Congratulations!
Feel free to explore the sample app to try out the various features of the SDK. Start by clicking the FB.Init button at the top of the sample, which will enable the other features of the sample. As a next step, modify the code included in the sample and add it to your game project; this will get your Facebook integration off to a flying start.
For more details on integrating the Facebook SDK into your Unity game, check out the SDK reference and SDK Examples. And if you'd like to see how easy it is to deploy to Facebook Canvas and iOS, check out their respective Getting Started guides.