How to use Facebook v4 with Android Studio

While I’m thrilled that we can now use Android Studio with enterprise projects, the documentation is still a little hit and miss with regards to using plugins.  Facebook usage is a notable omission and it is surprising that v4 is still considered beta.

I’ve been successful getting a test app and my real app working with Facebook.  It is actually pretty straightforward which comes with a bit of relief.  The short answer is you need to import the Facebook project that is part of the enterprise distribution.  Here’s the step-by-step:

  1.  In your libs directory add the plugin.facebook.v4.jar file.  You SHOULD NOT have any of the other facebook jars like bolts-android-1.1.2.jar or facebook_sdk.jar.

  2.  Add the following to your app’s gradle.properties file (these values are copied from Facebook’s gradle.properties)

ANDROID_BUILD_MIN_SDK_VERSION=9
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.2
ANDROID_BUILD_SDK_VERSION=21

  1. In Android Studio, select File->New->Import Module…

  2. Browse to the Facebook code in the CoronaEnterprise folder in applications:

/Applications/CoronaEnterprise/Plugins/sdk-facebook/android/4.5.0/facebook

  1. If you don’t already have tools and sdk version 21 installed, you’ll get errors along with links to perform the install.

  2.  In your build.gradle for the app, add the following to dependencies:

compile project(’:facebook’)

  1. Clean / Rebuild / Run  (It sometimes takes me a couple of clean, rebuild passes to get everything going)

Thank you, that worked for me.

In case anyone else has this issue in future, the only problem I had after doing this was a duplicate file error. For some reason the Facebook lib was duplicating it’s mdpi/hdpi/xhdpi/xxhdpi folders  into mdpi-v4, hdpi-v4 etc. Since it also kept the original, it then threw the error. I just changed the original folder names to have the -v4 suffix, and that solved the problem. No idea why it was doing this in the first place though.

I’ve noticed that the v4 docs for Android Enterprise only have the Ant method.  

Would someone at Corona be able to add the Android studio method as described by nandgate now that Corona Enterprise officially supports Android Studio? I think it will definitely save some headaches for people in future.

Hey everyone,

The Facebook-v4 (now known as simply “Facebook”) plugin is now out of beta:

https://coronalabs.com/blog/2016/10/28/facebook-plugin-update-we-are-out-of-beta/

And with that, the Enterprise Setup instructions have been updated for Android Studio:

https://docs.coronalabs.com/plugin/facebook-v4/index.html#android-1

The instructions for the stable release of the Facebook plugin supersede what nandgate had originally posted for daily build 2016.2932 and above.

Consult the new Facebook Versioning/Upgrade guide for more info:

https://docs.coronalabs.com/plugin/facebook-v4/fbUpgrade.html

Thanks ajay for the sharing. It helped me.

Thank you, that worked for me.

In case anyone else has this issue in future, the only problem I had after doing this was a duplicate file error. For some reason the Facebook lib was duplicating it’s mdpi/hdpi/xhdpi/xxhdpi folders  into mdpi-v4, hdpi-v4 etc. Since it also kept the original, it then threw the error. I just changed the original folder names to have the -v4 suffix, and that solved the problem. No idea why it was doing this in the first place though.

I’ve noticed that the v4 docs for Android Enterprise only have the Ant method.  

Would someone at Corona be able to add the Android studio method as described by nandgate now that Corona Enterprise officially supports Android Studio? I think it will definitely save some headaches for people in future.

Hey everyone,

The Facebook-v4 (now known as simply “Facebook”) plugin is now out of beta:

https://coronalabs.com/blog/2016/10/28/facebook-plugin-update-we-are-out-of-beta/

And with that, the Enterprise Setup instructions have been updated for Android Studio:

https://docs.coronalabs.com/plugin/facebook-v4/index.html#android-1

The instructions for the stable release of the Facebook plugin supersede what nandgate had originally posted for daily build 2016.2932 and above.

Consult the new Facebook Versioning/Upgrade guide for more info:

https://docs.coronalabs.com/plugin/facebook-v4/fbUpgrade.html

Thanks ajay for the sharing. It helped me.