Android facebook SDK 执行错误 java.lang.NoClassDefFoundError?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3563593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:46:35  来源:igfitidea点击:

Android facebook SDK doing error java.lang.NoClassDefFoundError?

androidfacebooknoclassdeffounderror

提问by Fabien

I have just downloaded the facebook SDK from http://github.com/facebook/facebook-android-sdkI unpack it from git and opened Eclipse. I then created a new project using existing source and selected the facebook directory. So the sdk project came up correctly (i think). Then I created a new project again using existing source and selected the "Simple" example. Its came up with errors. I went in the properties and selected Build Path section and added the facebook SDK project and applyed. All the errors disappear. I then tried to run the Example but im getting an exception on the first call to facebook SDK function ! Exception is NoClassDefFoundError. Its seems that at runtime it cannot find the class of the SDK. How come ? Any suggestions ? Someone did sucessfully run this example ? Any help would be greatly appreciated.

我刚刚从http://github.com/facebook/facebook-android-sdk下载了 Facebook SDK我从 git 中解压它并打开 Eclipse。然后我使用现有源创建了一个新项目并选择了 facebook 目录。所以sdk项目正确出现(我认为)。然后我使用现有源再次创建了一个新项目并选择了“简单”示例。它提出了错误。我进入了属性并选择了构建路径部分并添加了 facebook SDK 项目并应用。所有的错误都消失了。然后我尝试运行示例,但我在第一次调用 facebook SDK 函数时遇到异常!异常是 NoClassDefFoundError。它似乎在运行时找不到 SDK 的类。怎么来的 ?有什么建议 ?有人成功运行了这个例子吗?任何帮助将不胜感激。

回答by Dumitru Hristov

Right click on the Project. Choose Properties -> Android. Under Library click on the Add... button and select the path to the Facebook SDK Project.

右键单击项目。选择属性 -> Android。在库下单击添加...按钮并选择 Facebook SDK 项目的路径。

回答by Mohamed A.Karim

I had your same problem, and there was a suggestion in another question thread to export the Android Facebook SDK as a jar file and add that file to your project.

我遇到了同样的问题,并且在另一个问题线程中提出了将 Android Facebook SDK 导出为 jar 文件并将该文件添加到您的项目的建议。

Although some people said that the previous solution worked with them, it didn't work with me!

虽然有人说以前的解决方案对他们有效,但对我无效!

The only thing worked with me is: coping the Android Facebook SDK six classes into my project and that solved my problem.

唯一对我有用的是:将 Android Facebook SDK 六个类处理到我的项目中,这解决了我的问题。

Steps:

脚步:

1- I simply copied the following 6 classes from the Android SDK into my project AsyncFacebookRunner.java DialogError.java Facebook.java FacebookError.java FbDialog.java Util.java

1-我只是将以下 6 个类从 Android SDK 复制到我的项目 AsyncFacebookRunner.java DialogError.java Facebook.java FacebookError.java FbDialog.java Util.java

2- I've also copied the facebook_icon.png file from the drawable folders to my drawable folders.

2- 我还将 facebook_icon.png 文件从 drawable 文件夹复制到我的 drawable 文件夹中。

3- I imported my R.java class in the the copied FbDialog.java class.

3- 我在复制的 FbDialog.java 类中导入了我的 R.java 类。

My advice is to try the jar solution first (as it is the neat way to be a developer), if it didn't work with you, then try my solution (as it is a way to solve the problem).

我的建议是先尝试 jar 解决方案(因为它是成为开发人员的好方法),如果它对您不起作用,那么请尝试我的解决方案(因为它是解决问题的一种方法)。

Thanks and hopefully it will solve your problem.

谢谢,希望它能解决你的问题。

Mohamed.

穆罕默德。

回答by dangel

I managed to overcome this error by doing a clean build for both my project and facebook library (referenced) project.

我通过为我的项目和 facebook 库(引用)项目进行干净的构建来克服这个错误。

The steps:

步骤:

On Eclipse:

在日食上:

1) Select Project -> Clean
2) Select both your project and facebook sdk project
3) select OK

回答by user_15

I too faced the same problem. I was able to overcome this issue by placing the Facebook SDK library as well as my project(to which I want to link the Facebook SDK) within the same workspace. Now go to your project->right click->properties->android->scoll down->add->select the path to facebook SDK->press ok.

我也面临同样的问题。通过将 Facebook SDK 库和我的项目(我想将 Facebook SDK 链接到该项目)放在同一工作区中,我能够克服这个问题。现在转到您的项目->右键单击->属性->android->向下滚动->添加->选择facebook SDK的路径->按确定。

This way you can link the Facebook SDK to your project. Only adding the Facebook jar will result in an exception as this does not contain all the classes.

通过这种方式,您可以将 Facebook SDK 链接到您的项目。仅添加 Facebook jar 将导致异常,因为它不包含所有类。

回答by Khurram

I also had this exception and tried almost everything i found. But then i copied the facebook sdk project to my workspace folder and then referenced it from there in my project and it worked.

我也有这个例外并尝试了几乎所有我发现的东西。但是后来我将 facebook sdk 项目复制到我的工作区文件夹,然后在我的项目中从那里引用它并且它起作用了。

Don't know why this happened, this made no sense to me as i was providing it the path while adding reference but anyways, It solved the problem.

不知道为什么会发生这种情况,这对我来说毫无意义,因为我在添加参考时为其提供了路径,但无论如何,它解决了问题。

回答by Diego Caprioli

I had this same problem. I solved it just by following these steps:

我有同样的问题。我只是按照以下步骤解决了它:

  1. Remove all the sample projects and the Facebook SDK from Eclipse
  2. Import the SDK and sample projects again, but this time, using the "Copy projects into workspace" option checked.
  3. Rebuild the SDK and the sample projects
  4. Working!
  1. 从 Eclipse 中删除所有示例项目和 Facebook SDK
  2. 再次导入 SDK 和示例项目,但这次使用选中的“将项目复制到工作区”选项。
  3. 重新构建 SDK 和示例项目
  4. 在职的!

回答by 5agado

Try to mark the check-boxes in Properties -> Java Build Path -> Order and Export.

尝试标记Properties -> Java Build Path -> Order and Export 中的复选框。

I had the same problem with the UiLifecycleHelper, and checkig both the Android Dependenciesand the android-support-v4.jarworked perfectly. Better to run a clean after that.

我有同样的问题UiLifecycleHelper,并且检查Android 依赖项android-support-v4.jar工作得很好。最好在那之后运行一次清洁。

回答by ?iki? Nenad

I had similar problems. I am building one my lib project (with activities) and my main project using this lib. I had these problems. I had added the lib under the Project properties/Android section and at the bottom, as suggested correctly before, but this wasn't enough (note that both projects were compiling good). I had to change the lib project and use the full path to the layout as:

我有类似的问题。我正在构建一个我的 lib 项目(带有活动)和我使用这个 lib 的主项目。我有这些问题。我已经按照之前正确的建议在项目属性/Android 部分和底部添加了 lib,但这还不够(请注意,两个项目都编译良好)。我不得不更改 lib 项目并使用布局的完整路径:

setContentView(com.example.mylib.R.layout.activity_main1);

Note that using just R.layout wasn't enough, although I have defined the:

请注意,仅使用 R.layout 是不够的,尽管我已经定义了:

import com.example.mylib.R;

Valid alternative is however:

然而,有效的替代方案是:

import com.example.mylib.R.layout;
setContentView(layout.activity_main1);

Using Eclipse.

使用 Eclipse。

hth to someone

对某人

回答by Vrajesh

download bolts-android1.1.2and put into \libs folder. then open the project properties-> java Build Path-> Project tab , Add Facebook SDK. (Facebook SDK libs must be attached with project)

下载bolts-android1.1.2并放入 \libs 文件夹。然后打开项目属性-> java Build Path-> Project tab ,添加Facebook SDK。(Facebook SDK 库必须随项目附上)

回答by user1555123

The new facebook SDK already had android.support.V4.jar.

新的 facebook SDK 已经有 android.support.V4.jar。

And when you create a new android application, even that contains one.

当你创建一个新的 android 应用程序时,即使它包含一个。

Hence when you check the console, you get error message called JAR mismatch.

因此,当您检查控制台时,您会收到称为 JAR 不匹配的错误消息。

In that case select properties of android project -> Java Build path ->

在这种情况下,选择 android 项目的属性 -> Java Build path ->

Select Library tab -> Remove android.support.V4.jar Select Order and Export and uncheck -> Reference libraries (android.support.V4.jar)

选择库选项卡 -> 删除 android.support.V4.jar 选择订单和导出并取消选中 -> 参考库(android.support.V4.jar)

This will fix the issue.

这将解决问题。