简体   繁体   English

Eclipse中的Android Facebook SDK 4

[英]Android Facebook SDK 4 in Eclipse

Are there some way to import the new Facebook SDK for Android to Eclipse without Gradle or Maven (something like the past way)? 有没有办法在不使用Gradle或Maven的情况下将新的Facebook SDK for Android导入Eclipse(类似于过去的方式)? I've been watching some pages but i don't find a the way. 我一直在看一些页面,但我找不到方法。

Thanks 谢谢

I also have faced this problem, so I will write a short guide, how to install it in Eclipse. 我也遇到过这个问题,所以我会写一篇简短的指南,如何在Eclipse中安装它。

Step 1. Import to Eclipse 步骤1.导入Eclipse

First of all, download the latest version of SDK (on current moment it is 4.0). 首先,下载最新版本的SDK(目前它是4.0)。 Unzip it to a folder. 将其解压缩到一个文件夹。

Open Eclipse, click the right mouse button in "PackageExplorer" and choose "Import" . 打开Eclipse,在"PackageExplorer"单击鼠标右键,然后选择"Import" After that, go to "Android" -> "Existing Android Code Into Workspace" . 之后,转到"Android" - > "Existing Android Code Into Workspace"

在此输入图像描述

Now click "Browse" and choose unzipped SDK folder, and deselect all other found projects, except from the "facebook" (it is an SDK). 现在单击"Browse"并选择解压缩的SDK文件夹,并取消选择除"facebook" (它是SDK)之外的所有其他找到的项目。 Other included projects are just samples, and you don't need them now. 其他包含的项目只是样本,您现在不需要它们。

在此输入图像描述

You may select "copy project to workspace" checkbox, if you need this. 如果需要,可以选中“将项目复制到工作区”复选框。

Step 2. Fixing errors 第2步。修复错误

After importing, we will see, that the whole facebook SDK package are in errors: 导入后,我们将看到整个facebook SDK包有错误:

在此输入图像描述

But if we look closer, and open one of marked as error classes, we will find, that SDK tried to import support.v4 library : 但是如果我们仔细观察并打开其中一个标记为错误的类,我们会发现,SDK试图导入support.v4 library

在此输入图像描述

It required for properly compilation. 它需要正确编译。 You can find instructions how to download it using Android SDK Manager here . 您可以在此处找到有关如何使用Android SDK Manager下载它的说明。

After it downloading, you can find it in your Android sdk folder: <sdk>/extras/android/support/v4 . 下载后,您可以在Android sdk文件夹中找到它: <sdk>/extras/android/support/v4 Then add it to the facebook SDK project: right mouse click on SDK project -> "Properties" -> "Java Build Path" -> "Libraries" -> "Add External JARs" , and choose android-support-v4.jar from it's folder. 然后将其添加到facebook SDK项目:右键单击SDK项目 - > "Properties" - > "Java Build Path" - > "Libraries" - > "Add External JARs" ,然后从中选择android-support-v4.jar它的文件夹。

在此输入图像描述在此输入图像描述在此输入图像描述

After that a lot of errors will be gone: 之后很多错误都会消失:

在此输入图像描述

But, there are other errors. 但是,还有其他错误。 So we are going to another class, and found it error code piece. 所以我们要去另一个类,发现它是错误代码片。 Move mouse pointer on it, and Eclipse will show you the hint, of what kind of error you are facing. 将鼠标指针移动到它上面,Eclipse将向您显示您所面临的错误类型的提示。 It says that your compliance Java must be version 1.7. 它表示您的合规性Java必须是1.7版。 Allow Eclipse do it by clicking " Change project ..." , or do it manually by going to "Properties" -> "Java Complier" -> "Compiler compilance level" -> "1.7" . 允许Eclipse通过单击“ Change project ..."执行此操作,或者通过转到"Properties" - > "Java Complier" - > "Compiler compilance level" - > "1.7"手动执行此操作。

在此输入图像描述

OR 要么

在此输入图像描述

Moving ahead. 继续前进。 Now we are facing only one kind of error, that says that the FB SDK can't find required Bolts Android library. 现在我们只面临一种错误,即FB SDK无法找到所需的Bolts Android库。

在此输入图像描述

We are going to google, found it compiled jar in a repository . 我们要google,在存储库中找到它编译的jar。 Choose the latest version (for current moment it's 1.2.0, but SDK gradle file is using 1.1.4, so you may choose that), and download the jar. 选择最新版本(目前它是1.2.0,但SDK gradle文件使用1.1.4,所以你可以选择),然后下载jar。 Now add it to the facebook SDK as external lib, as we do it before. 现在将它作为外部库添加到facebook SDK,就像我们之前做的那样。

在此输入图像描述

Voila! 瞧! Ther are no errors anymore! Ther不再是错误!

在此输入图像描述

Also don't forget to set in the facebook SDK project "Properties" -> "Android" , that it is a Library. 另外别忘了在facebook SDK项目中设置"Properties" - > "Android" ,它是一个库。

在此输入图像描述

Just for ensurance, close/re-open the SDK project and clean it ( "Eclipse menu" -> "Project" -> "Clean" ), so all files can build properly. 只是为了保证,关闭/重新打开SDK项目并清理它( "Eclipse menu" - > "Project" - > "Clean" ),这样所有文件都可以正确构建。

Step 3. Add it to the Android project 第3步。将其添加到Android项目中

Now you can try to add it to your Android app. 现在,您可以尝试将其添加到Android应用中。 Go to your Android app project "Properties" -> "Android" -> "Library" -> "Add" , and choose facebook SDK. 转到您的Android应用程序项目"Properties" - > "Android" - > "Library" - > "Add" ,然后选择Facebook SDK。

在此输入图像描述

Follow official tutorial , and set up your Android application project (don't forget to add all required elements to Manifest.xml). 按照官方教程 ,设置您的Android应用程序项目(不要忘记将所有必需的元素添加到Manifest.xml)。 Than you can use this tutorial to add LoginButton to your Activity. 您可以使用本教程将LoginButton添加到您的Activity中。 Try to build it. 尝试构建它。 It should run without problem. 它应该没有问题。

在此输入图像描述

你也可以使用下面的代码,它适用于我,同时使用Facebook SDK 4.7 链接

是的,您可以从此页面“ 入门获取可下载的SDK,然后选择已准备好的Facebook应用程序,然后单击下载适用于Android的Facebook SDK,解压缩包并记下文件夹的位置Enjoy

Both of the above answers/comments are incorrect. 以上两个答案/评论均不正确。 The latest Facebook SDK ,4.0, is targeted at Android Studio and gradle. 最新的Facebook SDK 4.0是针对Android Studio和gradle的。

In particular, there are no external libs included in the downloaded project. 特别是,下载的项目中没有包含外部库。 They are configured as compile dependencies in the build.gradle file. 它们在build.gradle文件中配置为编译依赖项。

dependencies {
compile 'com.android.support:support-v4:[21,22)'
compile 'com.parse.bolts:bolts-android:1.1.4'

} }

You would need to create a libs folder in the facebook project directory and add the support-v4 and bolt-android jars to it and then add the jars to your build path. 您需要在facebook项目目录中创建一个libs文件夹,并将support-v4和bolt-android jar添加到它,然后将jar添加到您的构建路径中。

I also encountered an issue with JDK Compliance. 我还遇到了JDK Compliance的问题。 My projects defaults were JDK 1.6 but the Facebook library requires JDK 1.7. 我的项目默认值是JDK 1.6,但Facebook库需要JDK 1.7。 The solution to that was to change the settings for the facebook project under the Java -> Compile settings. 解决方案是在Java - > Compile设置下更改facebook项目的设置。

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

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