导入android.support.v7.app无法解析
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24651232/
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
The import android.support.v7.app cannot be resolved
提问by peter_f
after updating to Eclipse Kepler, I haven't been able to add the support library appcompat. I've followed this instructionsand I still get the error The import android.support.v7.app cannot be resolvedon the following lines:
更新到 Eclipse Kepler 后,我一直无法添加支持库 appcompat。我已按照此说明操作,但仍然收到错误导入 android.support.v7.app 无法在以下几行解析:
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
I have added the appcompat project, added both jars to the Build Path, selected them on the Order and Export tab, and added the library project in the main project.
我已经添加了 appcompat 项目,将两个 jars 添加到构建路径,在 Order and Export 选项卡上选择它们,并在主项目中添加库项目。
I copied the v4 library to the libs folder in the main project, but I don't know what else to do or check. Does anyone have any suggestions??
我把v4库复制到了主项目的libs文件夹下,但不知道还能做什么或检查什么。有没有人有什么建议??
Thank you!
谢谢!
回答by Matheus Santos
After you add appcompat_v7 to your dependencies, be sure that the libs
folder from your project are empty. By default, an android-support-v4.jar is created when you define your project, so this will cause conflict when you declare appcompat_v7 library as your dependency.
将 appcompat_v7 添加到依赖项后,请确保libs
项目中的文件夹为空。默认情况下,在您定义项目时会创建一个 android-support-v4.jar,因此当您将 appcompat_v7 库声明为您的依赖项时,这会导致冲突。
So, the first thing you need to do is check the folder .../My_Project/libs
and fearlessly delete the file android-support-v4.jar
.
因此,您需要做的第一件事就是检查文件夹.../My_Project/libs
并无所畏惧地删除文件android-support-v4.jar
。
Then, add the appcompat_v7 library as a dependency of your project: To do this, if you are using Eclipse:
然后,将 appcompat_v7 库添加为项目的依赖项: 为此,如果您使用的是 Eclipse:
- Right click in your project folder, located in the Navigator.
- Click in properties, in the final of the list.
- In the Properties window, select the Android option (left menu).
- In the box Library, add your new reference.
- 右键单击位于导航器中的项目文件夹。
- 单击列表最后的属性。
- 在“属性”窗口中,选择 Android 选项(左侧菜单)。
- 在框库中,添加您的新参考。
If you are using Android Studio, you can follow the steps mentioned in the @Joey Garcia's comment.
如果您使用的是 Android Studio,则可以按照@Joey Garcia 的评论中提到的步骤进行操作。
Support Library Setup - https://developer.android.com/tools/support-library/setup.html
支持库设置 - https://developer.android.com/tools/support-library/setup.html
Let me know if it helped you. Good Luck!
让我知道它是否对你有帮助。祝你好运!
回答by Joey Garcia
Peter, I had the same problem and this is how I fixed it in Android Studio.
彼得,我遇到了同样的问题,这就是我在 Android Studio 中修复它的方法。
1) Right-Mouse click the Project from the Project Window Pane and select Open Module Settings
1) 鼠标右键单击项目窗口窗格中的项目,然后选择打开模块设置
2) On the left side, select app, then select the Dependencies tab on the top right
2)在左侧,选择应用程序,然后选择右上角的依赖项选项卡
3) Click the + button on the bottom left, select Library Dependency
3)点击左下角的+按钮,选择Library Dependency
4) Either type or select appcompat-v7 (com.android.support:appcompat-v7:20.0.0)
4) 输入或选择 appcompat-v7 (com.android.support:appcompat-v7:20.0.0)
5) Click ok on the Choose Library Dependency window
5) 在选择库依赖窗口中点击确定
6) Then Click ok, or apply on that Project Structure window.
6)然后单击确定,或在该项目结构窗口上应用。
Now, AS should be able to pull in the missing class.
现在,AS 应该能够引入缺失的类。
回答by Gueste
I'm new to Eclipse but I had the same error and somehow fixed it. I had 2 project, one of them fixed itself after restart or something, the first one i fixed by adding back the imports that somehow i or eclipse deleted. mine imports are:
我是 Eclipse 的新手,但我遇到了同样的错误并以某种方式修复了它。我有 2 个项目,其中一个在重新启动或其他事情后自行修复,第一个我通过添加回以某种方式我或 eclipse 删除的导入来修复。矿山进口是:
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
Are add any that you still need. Hope that helps
添加您仍然需要的任何内容。希望有帮助
回答by VVB
Just delete android-support-v4.jar
from libs
folder of your project. Rest of the things/errors will be gone. Eclipse will handle rest of the things.
只需android-support-v4.jar
从libs
项目文件夹中删除即可。其余的事情/错误将消失。Eclipse 将处理其余的事情。
回答by Srinivas Keerthiprakasam
Delete the android-support-v4.jar in lib folder.
删除 lib 文件夹中的 android-support-v4.jar。