android-support-v4.jar 未在 Eclipse 中正确导入

发布于 2024-12-22 07:11:33 字数 1661 浏览 1 评论 0原文

我正在尝试编译一个使用 android-support-v4.jar 及其包含的 Fragmentation 类的应用程序,但每当我尝试时,我都会收到消息编译发现代码有错误。所有错误都与 .JAR 中的不同 Fragmentation 类有关。我尝试按住 Ctrl 键单击项目文件夹,然后选择 Android Tools ->添加兼容性库,我不断收到此错误:

[2011-12-20 11:55:31 - Android Compatibility JAR not found:]
/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar

为什么它会在 Eclipse 的包内容中查找 .JAR?我进入了项目属性并进入了 Java 构建路径,并从 MainActivity/libs 文件夹导入了 .JAR,但这不起作用,然后我尝试从我的 SDK 目录导入它,但没有成功。我已经修复了项目属性并清理和构建了无数次,我重新启动了 Eclipse、我的计算机,重新下载并安装了 Eclipse、Android SDK 和 ADT,但仍然没有任何结果。我完全被难住了。


编辑


我已经完成了构建路径,并从 MainActivity/libs 和我的 SDK 目录导入了 .JAR。更糟糕的是,我在目录中添加了 .JAR,但它一直出现在错误中,但没有起作用。是什么让 Eclipse 在其应用程序包内容中查找它?


更新


因此,在修改后,项目内容没有显示任何错误,但 MainActivity 文件夹仍然显示有一个错误,但我仍然无法编译。

就像 nyah:

在此处输入图像描述


修订


所以我认为问题可能是“为什么 Eclipse 在Eclipse 应用程序的包内容而不是项目的 libs 目录或我用来将其作为外部 .JAR 导入的 Android SDK 目录?”


更新 #2


在修补之后,我现在只收到一个错误,它是在这个方法上:

@Override
public MenuItem setOnActionExpandListener(OnActionExpandListener onActionExpandListener) {
    // Noop
    return this;
}

快速修复说我应该删除 @Override 注释,但该方法必须重写超类方法。

这些是它显示的错误:

Multiple markers at this line
- The method setOnActionExpandListener(MenuItem.OnActionExpandListener) of type SimpleMenuItem must override a superclass method
- implements android.view.MenuItem.setOnActionExpandListener

I'm trying to get an app to compile that uses the android-support-v4.jar and the Fragmentation classes it contains, but I keep getting messages whenever I try to compile that there are errors in the code. All of the errors have to do with different Fragmentation classes that are in the .JAR. I have tried ctrl-clicking the project folder and then selecting Android Tools -> Add Compatibility Library and I keep getting this error:

[2011-12-20 11:55:31 - Android Compatibility JAR not found:]
/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar

Why would it be looking for the .JAR in Eclipse's Package Contents? I've gone into the project properties and went to the Java Build Path, and imported the .JAR from the MainActivity/libs folder, that didn't work, and then I tried to import it from my SDK directory, and that didn't work. I've fixed the project properties and cleaned and built it countless times, I've restarted Eclipse, my computer, re-downloaded and installed Eclipse, the Android SDK's and ADT and still nothing. I am completely stumped.


Edit


I've gone through the build path and imported the .JAR from both the MainActivity/libs and my SDK directory. For the hell of it I added the .JAR in the directory that keeps appearing in the errors and that hasn't worked. What's making Eclipse look for it in it's Application Package Contents?


Update


So after tinkering the project contents aren't showing any errors but the MainActivity folder still says that there is one and I still can't compile.

Like nyah:

enter image description here


Revision


So I think the question may be "Why is Eclipse looking for the .JAR in the Eclipse Application's package contents instead of the libs directory of the project or the Android SDK directory that I used to import it as an external .JAR?"


Update #2


I am only getting one error now after tinkering, it's on this method:

@Override
public MenuItem setOnActionExpandListener(OnActionExpandListener onActionExpandListener) {
    // Noop
    return this;
}

The Quick Fix says that I should delete the @Override annotation but that method must override a super class method.

These are the errors that it shows:

Multiple markers at this line
- The method setOnActionExpandListener(MenuItem.OnActionExpandListener) of type SimpleMenuItem must override a superclass method
- implements android.view.MenuItem.setOnActionExpandListener

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

梦亿 2024-12-29 07:11:33

看起来它正在这里寻找 jar :/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar

android-support-v4.jar 在/extras/android/ 中找到兼容性/v4

请确保将其添加为 java 构建路径中的外部 jar

Looks like it is looking for jar here :/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar

android-support-v4.jar is found in <sdk>/extras/android/compatibility/v4

Please make sure you add this as an external jar in the java build path

橙味迷妹 2024-12-29 07:11:33

我可以通过以下方式解决这个问题
1-从lib中删除“android-support-v4.jar”
2-右键单击项目名称选择“Android Tools”和“Add Support Library”

I could solve this problem by
1- delete "android-support-v4.jar" from lib
2- right click on the name of the project choose "Android Tools" and "Add Support Library"

不醒的梦 2024-12-29 07:11:33

如果仍然没有解决:
就像已经说过的,在 Eclipse 中转到您的 Project Properties > Java 构建路径 >库>添加External并从adk目录中获取一个。

如果尚未将 Java 1.6 设置为默认编译版本,请将其设置为默认编译版本。这应该可以解决您所描述的覆盖错误。

If this is still not solved:
Like already said, in Eclipse go to your Project Properties > Java Build Path > Libs > Add External and get the one from the adk directory.

Also set up Java 1.6 as your default compile version if you already haven't. This should solve the Override Errors you described.

稳稳的幸福 2024-12-29 07:11:33

事实证明,我的调试证书已经过期,所以我只需要删除 ~/.android/debug.keystore 并重新启动 Eclipse,一切就正常了。

It turns out that my Debug Certificate had expired so I just needed to delete ~/.android/debug.keystore and restart Eclipse and everything worked.

音盲 2024-12-29 07:11:33

我意识到这个问题已经得到解答,但这是一个已知问题,根据此处的评论 9,应该在 ADT-17 插件版本中修复:http://code.google.com/p/android/issues/detail?id=21488

另外,遇到此问题的人可以复制兼容JAR到它说找不到的位置。显然它在错误的位置查找(因为它检查的是 Eclipse 目录而不是 android-sdk 目录),因此目前简单的修复方法就是将包放在它想要找到的位置,即使它没有属于。

对我来说,这就像将 C:/android-sdk/extras/android/support/ 中的 v4 目录复制到 C:/eclipse/ 目录中一样简单。

I realize that this question has been answered, but this is a known issue that is supposed to be fixed in the ADT-17 plugin release according to comment 9 here: http://code.google.com/p/android/issues/detail?id=21488

In addition, people who have this problem can copy the compatibility JAR to the location it says it can't find it. Clearly it's looking in the wrong place (since it's checking the Eclipse directory rather than the android-sdk directory), so the simple fix, for now, is simply to put the package where it wants to find it, even though it doesn't belong.

For me it was as simple as copying the v4 directory within C:/android-sdk/extras/android/support/ into the C:/eclipse/ directory.

神回复 2024-12-29 07:11:33

我在 Ubuntu 中运行时遇到了同样的问题。转到工具->选项。
检查强制 https://... 到 http://
打开 Android SDK 管理器。检查附加 -> Android 支持库。

I had the same problem running in Ubuntu. Go to Tools->Options.
Check Force https://... to http://
Open Android SDK Manager. Check Extras->Android Support Library.

思慕 2024-12-29 07:11:33

类似的事情也发生在我身上。在 MainActivity.java 的顶部,我的下一个导入给出了错误:

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

在左侧的每一行中,他们都有灯泡提出一些建议。如果单击它,选项之一将是“修复项目设置”。然后,您将能够在修复导入的多个选项之间进行选择,您应该选择指定 android-support-v4.jar 的选项。

Something similar happened to me. At the top of MainActivity.java I had the next imports giving errors:

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

In each of the lines on the left they had the light bulb making some suggestions. If you click on it, one of the options will be "Fix project setup". You then will be able to choose between several options for fixing the imports, you should choose the one that specifies the android-support-v4.jar.

丑丑阿 2024-12-29 07:11:33

右键单击您的项目 -->选择android工具-->选择添加支持库并简单安装支持库。

Right click on ur project --> select android tools --> select add support library and simply installed the supporting libraries.

相思碎 2024-12-29 07:11:33

你尽量不做Android Tools->添加兼容库,并且只添加java构建路径库中的jar?。

我以这种方式使用这个 jar 库,它工作没有任何问题。

Do you try not to do Android Tools -> Add Compatibility Library, and only add the jar in java build path library?.

I use this jar library of this way and it works without any problem.

红衣飘飘貌似仙 2024-12-29 07:11:33

我也有同样的问题。

在项目属性:Java 构建路径:订单和导出选项卡下,未选中 android-support-v4.jar 旁边的框。我检查了该框,错误就消失了。

I had the same problem.

Under the project properties:Java Build Path:Order and Export tab, the box next to android-support-v4.jar wasn't checked. I checked the box, and the error went away.

枯寂 2024-12-29 07:11:33

另一个需要注意的是在没有管理员权限的情况下在 Windows 7 中运行 Android SDK Manager。它会尝试安装支持包,但总是失败,并且实际的包从未下载到

C:\Program Files (x86)\Android\android-sdk\extras\android\support\v4\android-support-v4.jar

Another caveat was running Android SDK Manager in Windows 7 without administrator privileges. It would try to install support package, but would always fail, and the actual package never got downloaded to

C:\Program Files (x86)\Android\android-sdk\extras\android\support\v4\android-support-v4.jar

屋檐 2024-12-29 07:11:33

解决方案:确保在 Android 项目创建期间(或创建后的 Manifest 文件中)为“Target SDK”和“Compile with”输入相同的 API。

Solution: Make sure that you enter the same API for "Target SDK" and "Compile with" during Android project creation (or in the Manifest file once created).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文