Cordova: Facebook Plugin for Android Build Error
I use Cordova 3.4 and the Cordova Facebook Plugin for Android to build a sample Cordova Facebook App on Android.
Here are the steps I did:
1 Create a blank Cordova application
2 edit Test/config.xml and inserted
<feature name="org.apache.cordova.facebook.Connect">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
3 Install the Facebook SDK for Android and the Facebook APK
4 From the Cordova Facebook Plugin folder copy ConnectPlugin.java from src/android/ into Test/platforms/android/src/org/apache/cordova/facebook/
5 From the Cordova Facebook Plugin folder copy the www/cdv-plugin-fb-connect.js and www/facebook-js-sdk.js into into your application's Test/www folder
6 go to Test/ and execute cordova build
The last step outputs the following error:
BUILD FAILED
/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools/ant/build.xml:601: The following error occurred while executing this line:
/Users/mg/Documents/Android/Plugins/facebook-android-sdk-3.8.0/facebook/build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
Total time: 0 seconds
Error code 1 for command: ant with args: debug,-f,/Users/mg/Documents/Android/Test/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/mg/Documents/Android/Test/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:112:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
How can I solve this problem?
The solution for your problem is in this line:
/Users/mg/Documents/Android/Plugins/facebook-android-sdk-3.8.0/facebook/build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
Your facebook SDK isn't finding the android SDK directory. So you need to run:
android update project --path /Users/mg/Documents/Android/Plugins/facebook-android-sdk-3.8.0/facebook
And try again.
I had the same problem, here what I did:
In the SDK facebook folder, create the local.properties file and put your path:
sdk.dir=/my/path/to/adt-bundle-linux-x86_64-20140702/sdk
You can copy from your local.properties of your main project.
Now, if want to work with cordova cli AND eclipse, you need to know that adt build and ant build are diferents, you can see here https://stackoverflow.com/a/19746506/1833734. So, here the trick:
If you want to use ant (cordova console):
ant clean
. Your main project is something like this: /path/to/my/cordova/project/platforms/android
cordova run
or cordova build
PS. Check the properties in Eclipse of main project, the facebook plugin add the facebook sdk library, and in my case the path was wrong, so I fixed adding my own path. This can generate a break in eclipse and cordova-cli.
If you need change to eclipse, you need to do this:
So, you will need to use this steps aways you need to change of eclipse to cordova-cli or vice versa.
Last tip: Don't forget to refresh (f5) eclipse projects after use cordova cli.
链接地址: http://www.djcxy.com/p/53414.html