Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import facebook SDK to cordova/phonegap project

I'm creating my first app using cordova 3.3.0 (aka phonegap). Everything's all right : I can run project on to Android Device Emulator and on to my mobile.

I'd like to use the facebook connect plugin : https://github.com/phonegap/phonegap-facebook-plugin

But all the documentation I read (particularly : https://developers.facebook.com/docs/android/getting-started) explains how to set up the Facebook SDK through Eclipse. I've also found doc on how to install in Androïd Studio.

I don't want to install neither of them, I do all in command line since I like to know how things works (at least for my first projetc ...).

So the question is : how do I import facebook SDK into my cordova project ?

Thanks for your ideas !

like image 346
hugsbrugs Avatar asked Jan 20 '14 21:01

hugsbrugs


2 Answers

Alright I found the answer, was struggling with the exact same problem. I was actually trying to get an ionic cordova project to use the facebook plugin

You have to go inside the Platform/android folder of your cordova project. At this point , you are just dealing with a regular android project

run the following command

android update project --target 3 --path C:\Users\<yourname>\Documents\Projects\<projectName>\ionic\platforms\android --library ../../../../facebook-android-sdk-3.7/facebook

Alright a couple of tricks

  • The --library argument needs to be relative to your android project. And the library argument should refer to the facebook SDK you downloaded ( as part of the facebook plugin instructions)
  • You have to have API level 8 on the android SDK
  • Once the command completes, go to local.properties and check if the sdk.dir is set properly. Mine had double slashes, I had to fix that
  • go to project. properties and you should see something like the following

    android.library.reference.1=CordovaLib

    android.library.reference.2=../../../../facebook-android-sdk-3.7/facebook target=android-18'

Hope this helps someone, I'm not too fond of using eclipse for phonegap either.

like image 142
Abdullah Choudhury Avatar answered Nov 14 '22 17:11

Abdullah Choudhury


Faced also the same problem today with cordova 3.3. Solution is similar to the other one given, maybe can be helpful. I am on linux environemnt

I managed to build by:

installing the plugin

cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="yourvalues" --variable APP_NAME="yourvalues"
cd /platforms/android

add this line to project.properties

android.library.reference.2=FacebookLib

update the project

android update project --subprojects --path . --target "android-19"

Then compiled successfully with

cordova build
like image 35
dawez Avatar answered Nov 14 '22 18:11

dawez