3. Setup gdx facebook - TomGrill/gdx-facebook GitHub Wiki

gdx-facebook installation is rather easy.

Core

Add dependency to build.gradle

compile "de.tomgrill.gdxfacebook:gdx-facebook-core:1.4.1"

Android

Add this to your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

<application
    
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />

    <activity android:name="com.facebook.FacebookActivity"
          android:configChanges=
                 "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:label="@string/app_name" />
    
</application>

Add this to your /res/values/strings.xml and replace 0123456789 with your App ID.

<string name="facebook_app_id">0123456789</string>

ONLY IF, you use the FragmentActivity setup you have to make sure the calls on onActivityResult() are passed to your GameFragment like this:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        gameFragment.onActivityResult(requestCode, resultCode, data);
    }

Add dependency to build.gradle

compile "de.tomgrill.gdxfacebook:gdx-facebook-android:1.4.1"

IMPORTANT facebook-android-sdk comes as .aar file. Some IDEs (f.e. Eclipse) are not capable of handling this file type. That means you have to start your app using the command line to make it work:

Linux/Max:

./gradlew android:installDebug android:run

Windows:

gradlew android:installDebug android:run

iOS RoboVM

Add this to your Info.plist.xml and replace 0123456789 (twice!, fb-prefix in 2nd part is correct!) and YOUR_FACEBOOK_APP_NAME accordingly.

<key>FacebookAppID</key>
<string>0123456789</string>
<key>FacebookDisplayName</key>
<string>YOUR_FACEBOOK_APP_NAME</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
    <string>fb0123456789</string>
</array>
</dict>
</array>

If you build for iOS 9 then also add:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

<key>NSPhotoLibraryUsageDescription</key>
<string>{human-readable reason for photo access}</string>

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

Add this to your robovm.xml

<forceLinkClasses>    
    <pattern>de.tomgrill.gdxfacebook.ios.IOSFacebookLoader</pattern>
</forceLinkClasses>

<frameworks>
    ...  other frameworks ...
    <framework>FBSDKCoreKit</framework>
</frameworks>
<frameworkPaths>
    <path>libs</path>
</frameworkPaths>

Add this to your IOSLauncher

@Override
public void didBecomeActive(UIApplication application) {
    super.didBecomeActive(application);
    FBSDKAppEvents.activateApp();
}


@Override
public boolean openURL(UIApplication app, NSURL url, UIApplicationOpenURLOptions options) {
    return FBSDKApplicationDelegate.getSharedInstance().openURL(app, url, options.getSourceApplication(), options.getAnnotation());

}

@Override
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
    boolean finished = super.didFinishLaunching(application, launchOptions);
    FBSDKApplicationDelegate.getSharedInstance().didFinishLaunching(application, launchOptions);
    return finished;
}

Add this to your build.gradle

compile "de.tomgrill.gdxfacebook:gdx-facebook-ios:1.4.1"

Finally you have to add the Facebook iOS SDK to your iOS project:

  1. Download the Facebook iOS SDK 4.15.1 here: https://developers.facebook.com/docs/ios/downloads (Newer version might work, but are not official compatible with mobidevelop-robopods.)
  2. Create a folder called libs in your ios project.
  3. Copy all folders, which are ending with .framework, from the zip into the created libs folder.

When in doubt, compare to the gdx-facebook sample app: https://github.com/TomGrill/gdx-facebook-app

iOS MOE

Requires: MOE 1.3.6+ and libGDX 1.9.6+

Add this to your ios-moe/xcode/ios-moe/Info.plist and replace 0123456789 (twice!, fb-prefix in 2nd part is correct!) and YOUR_FACEBOOK_APP_NAME accordingly.

<key>FacebookAppID</key>
<string>0123456789</string>

<key>FacebookDisplayName</key>
<string>YOUR_FACEBOOK_APP_NAME</string>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb0123456789</string>
        </array>
    </dict>
</array>

<key>NSPhotoLibraryUsageDescription</key>
<string>Cause I can</string>

Add this to your IOSLauncher

@Override
public void applicationDidBecomeActive(UIApplication application) {
    FBSDKAppEvents.activateApp();
    super.applicationDidBecomeActive(application);
}

@Override
public boolean applicationOpenURLOptions(UIApplication app, NSURL url, NSDictionary<String, ?> options) {
    return ((FBSDKApplicationDelegate)FBSDKApplicationDelegate.sharedInstance()).applicationOpenURLOptions(app, url, options);
}

@Override
public boolean applicationDidFinishLaunchingWithOptions(UIApplication application, NSDictionary<?, ?> launchOptions) {
    ((FBSDKApplicationDelegate) FBSDKApplicationDelegate.sharedInstance()).applicationDidFinishLaunchingWithOptions(application, launchOptions);
    return super.applicationDidFinishLaunchingWithOptions(application, launchOptions);
}

Add this to your build.gradle

compile "de.tomgrill.gdxfacebook:gdx-facebook-ios-moe:1.4.1"

Finally you have to add the Facebook iOS SDK to your iOS project:

Variant A (Using cocoapods, recommended)

  1. Add 'FBSDKCoreKit', 'FBSDKLoginKit', and 'FBSDKShareKit' to your pod file and install. Done.

Only, if you do not have a pod file yet:

Open a terminal window and go to: /project-root/ios-moe/xcode

Enter pod init

Add the frameworks and make sure your podfile looks kinda like this. Inclusive the post_install do |installer| ... part at the end.

Example:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'ios-moe' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!

  # Pods for ios-moe
  pod 'FBSDKCoreKit'
  pod 'FBSDKLoginKit'
  pod 'FBSDKShareKit'


end

target 'ios-moe-Test' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for ios-moe-Test

end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

Run pod install

DONE

Variant B (Manual adding the frameworks)

  1. Download the Facebook iOS SDK 4.23.0 here: https://developers.facebook.com/docs/ios/downloads (Newer version might work as well)
  2. Open yourproject/ios-moe/xcode/ios-moe.xcodeproj with XCode (DoubleClick from Finder f.e.)
  3. Drag the Bolts.framework, FBSDKCoreKit.framework, FBSDKLoginKit.framework, and FBSDKShareKit.framework files into the Frameworks group of Xcode's Project Navigator. (I prefer copying, referencing should work as well).

Your Framework group should look like this now:

  1. Go to the Build Settings of your XCode project and open the Other Linker Flags row. Double click the right part after the plus sign for Debug and Release. Add a new entry: -ObjC

  1. Go back to IntelliJ (should be similar to other IDEs which have the MOE plugin installed, get it here if you need it: https://github.com/multi-os-engine)
  2. Navigate to ios-moe/xcode/ios-moe.xcodeproj and open project.pbxproj file. Enable Copy CA Certificates (if needed in test as well)

When in doubt, compare to the gdx-facebook sample app: https://github.com/TomGrill/gdx-facebook-app

Desktop

compile "de.tomgrill.gdxfacebook:gdx-facebook-desktop:1.4.1"

GWT / HTML

GWT is currently experimental!!

compile "de.tomgrill.gdxfacebook:gdx-facebook-html:1.4.1:sources"
compile "de.tomgrill.gdxfacebook:gdx-facebook-core:1.4.1:sources"

Edit your GdxDefinition.gwt.xml in the html module and add this line:

<inherits name='de.tomgrill.gdxfacebook.html.gdx_facebook_gwt' />
⚠️ **GitHub.com Fallback** ⚠️