简体   繁体   English

在Android应用程序中引用Facebook SDK

[英]Reference Facebook SDK in Android application

I am following Getting Started with the Facebook SDK for Android , at step 6, the FacebookSDK needs to be linked to my Android Project. 我正在遵循适用于Android的Facebook SDK入门 ,在步骤6中,需要将FacebookSDK链接到我的Android项目。 However I get some unknown error and I'm unable to get details as to why or how to fix it. 但是,我收到一些未知的错误,并且无法获得有关为什么或如何解决此问题的详细信息。

I reference the Facebook SDK as follows: 我参考以下Facebook SDK:

在此处输入图片说明

However when I run the application, the console displays a message stating the FacebookSDK.apk cannot be found. 但是,当我运行该应用程序时,控制台会显示一条消息,指出找不到FacebookSDK.apk。 And my application throws a class not found exception. 而且我的应用程序抛出未找到的类异常。

Upon inspecting the project setup I found this: 在检查项目设置后,我发现:

在此处输入图片说明

I don't have much experience with linking projects. 我在链接项目方面经验不足。 I don't know what the red error means, also the project is marked with a question mark. 我不知道红色错误是什么意思,而且该项目还标有问号。

I have done and checked the following with no luck: - The FacebookSDK is part of my workspace. 我已经完成并没有运气检查以下内容:-FacebookSDK是我的工作区的一部分。 (I can compile the sample projects) (我可以编译示例项目)

  • Cleaned and rebuilt the workspace. 清理并重建工作区。

  • Recreated the workspace and repeated the entire process. 重新创建工作区并重复整个过程。

  • Included FacebookSDK.jar in my project's bin directory. 在我项目的bin目录中包含了FacebookSDK.jar。

  • The FacebookSDK file were not copied to my workspace, I only referenced it as per the Getting started guide. 没有将FacebookSDK文件复制到我的工作区,我仅根据《入门指南》对其进行了引用。

So I'm still not sure what caused the problem but I found a workaround after trying several steps without any luck: 因此,我仍然不确定是什么引起了问题,但是尝试了几步却没有任何运气之后,我找到了一种解决方法:

  • Created new workspace 创建新的工作区
  • Changed target built to be Android 2.2 (Froyo), the same as the built for the Facebook SDK 将目标更改为Android 2.2(Froyo),与针对Facebook SDK的目标相同
  • Rebuilt Project 重建项目
  • Clean Project 清洁项目

I carried on with the tutorial and added the imports such as 我继续进行本教程,并添加了诸如

import com.facebook.*;
import com.facebook.model.*;

Eclipse then suggested an auto-fix, to add the FacebookSDK to the build path of my application. Eclipse然后建议自动修复,以将FacebookSDK添加到应用程序的构建路径。 The FacebookSDK project was part of the same workspace. FacebookSDK项目是同一工作空间的一部分。

EDIT: This did solve the problem of the IDE not recognizing the classes in the FacebookSDK, however when I try to run, the FacebookSDK.apk is not found. 编辑:这确实解决了IDE无法识别FacebookSDK中的类的问题,但是当我尝试运行时,找不到FacebookSDK.apk。 This is because I referenced the SDK as a project when it should be a library. 这是因为当它应该是库时,我将SDK引用为项目。 I'm not sure how to fix. 我不确定如何解决。

FIX: Copy the FacebookSDK project files into the workspace and build all projects. FIX:将FacebookSDK项目文件复制到工作区中并生成所有项目。

I had the same problem after days and I couldn't find a answer, so after trying many things I resolved my issue by downloading another Eclipse, installing "ADT plugin", changing the workspace and importing it again 几天后我遇到了同样的问题,但找不到答案,因此在尝试了许多事情之后,我通过下载另一个Eclipse,安装“ ADT插件”,更改工作区并再次导入来解决了问题。

You can see here for how to download another Eclipse and install ADT 您可以在此处查看如何下载另一个Eclipse并安装ADT

After all that, open Eclipse and choose another workspace (I just worskpace2) and import the FaceBook SDK and the other projects 之后,打开Eclipse并选择另一个工作区(我只是worskpace2)并导入FaceBook SDK和其他项目

First import Your FacebookSDK Project in your current Project Explorer of eclipse to do so follow the procedure 首先在您当前的Eclipse项目浏览器中导入您的FacebookSDK项目,然后按照以下步骤进行操作

  1. Copy your facebook-android-sdk-3.0.1 in your workspace 在您的工作区中复制您的facebook-android-sdk-3.0.1

  2. File >> Import >> general >> existing projects into workspace 文件>>导入>>常规>>现有项目到工作区

  3. select rood directory to your workspace and select facebook-android-sdk-3.0.1 选择rood目录到您的工作区,然后选择facebook-android-sdk-3.0.1

  4. click on your FacebookSDK and click ok 单击您的FacebookSDK,然后单击确定

  5. Right Click on project and Properties >> android >> ADD >> FacebookSDK click apply and ok 右键单击项目和属性>> android >>添加>> FacebookSDK单击应用并确定

You have done.. 你做完了..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM