无法解决Import android.support.v7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24998368/
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 cannot be resolved
提问by Developer
I am new to Android. Currently, I have the adt-bundle-windows-x86-20131030.zip
(Windows 32 bit) installed - and have successfully installed the Android SDK and Eclipse. Also, I have updated everything in the Android SDK manager. Now, I am working in Android v-4.4.2
我是安卓新手。目前,我已经安装了adt-bundle-windows-x86-20131030.zip
(Windows 32 位) - 并且已经成功安装了 Android SDK 和 Eclipse。此外,我已经更新了 Android SDK 管理器中的所有内容。现在,我在 Android v-4.4.2 中工作
My project runs successfully, but when I import android.support.v7.app.ActionBarActivity;
and import android.support.v7.app.ActionBar;
the project won't debug. I get the error The Import android.support.v7 cannot be resolved
我的项目运行成功,但是当我导入android.support.v7.app.ActionBarActivity;
并且import android.support.v7.app.ActionBar;
项目不会调试时。我收到错误The Import android.support.v7 cannot be resolved
I searched in Google and installed Android Support Library
then added v7
in my project.
我在谷歌搜索并安装Android Support Library
然后添加v7
到我的项目中。
- File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"
- Project-> properties->Android. In the section library "Add" and choose "appCompat"
- 文件->导入(android-sdk\extras\android\support\v7)。选择“应用兼容”
- 项目-> 属性-> Android。在部分库中“添加”并选择“appCompat”
Screenshot
截屏
Successfully added in appCompat
but still I am still getting the error.
已成功添加,appCompat
但我仍然收到错误消息。
回答by ChristianCuevas
Go to your project in the navigator, right click on properties.
Go to the Java Build Path tab on the left.
Go to the libraries tab on top.
Click add external jars.
Go to your ADT Bundle folder, go to sdk/extras/android/support/v7/appcompat/libs.
Select the file android-support-v7-appcompat.jar
Go to order and export and check the box next to your new jar.
Click ok.
在导航器中转到您的项目,右键单击属性。
转到左侧的 Java Build Path 选项卡。
转到顶部的库选项卡。
单击添加外部罐子。
转到您的 ADT Bundle 文件夹,转到 sdk/extras/android/support/v7/appcompat/libs。
选择文件 android-support-v7-appcompat.jar
转到订购和导出并选中新罐子旁边的框。
单击确定。
回答by Jorgesys
I tried the answer described here but it doesn′t worked for me. I have the last Android SDK tools ver. 23.0.2 and Android SDK Platform-tools ver. 20
我尝试了此处描述的答案,但对我不起作用。我有最后一个 Android SDK 工具版本。23.0.2 和 Android SDK 平台工具版本。20
The support library android-support-v4.jar
is causing this conflict, just delete the library under /libs
folder of your project, don′t be scared, the library is already contained in the library appcompat_v7
, clean and build your project, and your project will work like a charm!
支持库android-support-v4.jar
导致了这个冲突,只需删除/libs
您项目文件夹下的库,不要害怕,库中已经包含该库appcompat_v7
,清理并构建您的项目,您的项目将像魅力一样工作!
回答by rosmianto
In my case, the auto-generated project appcompat_v7was closed. So just open up that project in Package Explorer.
就我而言,自动生成的项目appcompat_v7已关闭。所以只需在包资源管理器中打开该项目。
Hope this help.
希望这有帮助。
回答by JohannB
I had the same issue every time I tried to create a new project, but based on the console output, it was because of two versions of android-support-v4 that were different:
每次尝试创建新项目时,我都会遇到同样的问题,但根据控制台输出,这是因为 android-support-v4 的两个版本不同:
[2014-10-29 16:31:57 - HeadphoneSplitter] Found 2 versions of android-support-v4.jar in the dependency list,
[2014-10-29 16:31:57 - HeadphoneSplitter] but not all the versions are identical (check is based on SHA-1 only at this time).
[2014-10-29 16:31:57 - HeadphoneSplitter] All versions of the libraries must be the same at this time.
[2014-10-29 16:31:57 - HeadphoneSplitter] Versions found are:
[2014-10-29 16:31:57 - HeadphoneSplitter] Path: C:\Users\jbaurer\workspace\appcompat_v7\libs\android-support-v4.jar
[2014-10-29 16:31:57 - HeadphoneSplitter] Length: 627582
[2014-10-29 16:31:57 - HeadphoneSplitter] SHA-1: cb6883d96005bc85b3e868f204507ea5b4fa9bbf
[2014-10-29 16:31:57 - HeadphoneSplitter] Path: C:\Users\jbaurer\workspace\HeadphoneSplitter\libs\android-support-v4.jar
[2014-10-29 16:31:57 - HeadphoneSplitter] Length: 758727
[2014-10-29 16:31:57 - HeadphoneSplitter] SHA-1: efec67655f6db90757faa37201efcee2a9ec3507
[2014-10-29 16:31:57 - HeadphoneSplitter] Jar mismatch! Fix your dependencies
I don't know a lot about Eclipse. but I simply deleted the copy of the jar file from my project's libs folder so that it would use the appcompat_v7 jar file instead. This fixed my issue.
我对 Eclipse 了解不多。但我只是从我的项目的 libs 文件夹中删除了 jar 文件的副本,以便它使用 appcompat_v7 jar 文件。这解决了我的问题。
回答by Manuel Eduardo Romero
I fixed it adding these lines in the build.grandle (App Module)
我修复了它在 build.grandle(应用程序模块)中添加这些行
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) //it was there
compile "com.android.support:support-v4:21.0.+" //Added
compile "com.android.support:appcompat-v7:21.0.+" //Added
}
回答by Tvs
Recent sdk-manager's download does not contain android-support-v7-appcompat.jar But the following dir contains aar file C:\Users\madan\android-sdks\extras\android\m2repository\com\ android\support\appcompat-v7\24.2.1\appcompat-v7-24.2.1.aar This file can be imported by right-click project, import, select general, select archieve and finally select aar file. Even this does not solve the problem. Later remove 'import android.R' and add 'import android.support.v7.appcompat.*;' Follow this tutorial for other details: http://www.srccodes.com/p/article/22/android-hello-world-example-using-eclipse-ide-and-android-development-tools-adt-plugin
最近sdk-manager的下载不包含android-support-v7-appcompat.jar 但是下面的目录包含aar文件C:\Users\madan\android-sdks\extras\android\m2repository\com\android\support\appcompat-v7 \24.2.1\appcompat-v7-24.2.1.aar 这个文件可以通过右键project导入,导入,选择general,选择archieve,最后选择aar文件。即使这样也不能解决问题。后来删除'import android.R'并添加'import android.support.v7.appcompat.*;' 按照本教程了解其他详细信息:http: //www.srccodes.com/p/article/22/android-hello-world-example-using-eclipse-ide-and-android-development-tools-adt-plugin
回答by rcorbellini
completing the answer @Jorgesys, in my case it was exactly the same way but the export configuration was missing in the library:
完成答案@Jorgesys,在我的情况下,它的方式完全相同,但库中缺少导出配置:
- right click on appcompat-v7 project;
- properties;
- left tab, Java Build Path;
- Right tab, Order and export;
- Check classes.jar with appcompat-v7;
- 右键单击 appcompat-v7 项目;
- 特性;
- 左选项卡,Java 构建路径;
- 右侧选项卡,订购和导出;
- 使用 appcompat-v7 检查 classes.jar;