您的位置:首页 > 移动开发 > Android开发

android v7支持包导入问题,Support Error的正确解决方法

2015-05-18 18:11 429 查看
就是遇到这种报错时该怎么办:

Can’t Find Theme.AppCompat.Light for New Android

ActionBar Support Error retrieving parent for item: No resource found that matches the given name Theme.AppCompat.Light

结论很明确,v7支持包是带资源的库

Adding libraries with resources,文末给出了谷歌官方的解释。

所以你需要的是那几个jar包在各自的地方,并且 project build 和 java build 都配置正确,而不是在纠结mainfest里的版本问题。

首先,你的工程文件应该长下图这个样子,appcompat_v7工程是必须的,在创建时由eclipse在workspace下生成。如果不小心短路删除了,要再创建一个工程,或者有备份可通过File->import ->General->exsiting project 导入



必须注意:appcompat_v7和sdk下的appcompat中的文件夹是不完全一致的,至于为什么,俺也不清楚,有人知道么?

然后,在下图中有四个跟lib有关的地方



—— 1 和 3、4是互补的,4中的jar包会自动build到1中;同时,eclipse会自动识别出不是android SDK私有的jar包,并放入3中。

—— 而 2 中的jar包来自外部的project

这里就要提到 android 工程里的两个 build 配置路径: project build 和 java build

—— project build 里指定好project,然后就能将该工程中的jar包导入到上图的2中



最后,结论很明确,你需要的是那几个jar包在各自的地方,并且 project build 和 java build 都配置正确,而不是在纠结mainfest里的版本问题。

忽略掉httpmine后,就是你们要的正确的样子。然后alt+enter配置吧

楼下是谷歌正统的说法

https://developer.android.com/tools/support-library/setup.html#add-library

什么,你翻不了墙?怪我咯?

Adding libraries with resources

To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:


Using Eclipse

Create a library project based on the support library code:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project’s build path:Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the
appcompat
project, browse to
<sdk>/extras/android/support/v7/appcompat/
.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
In the new library project, expand the
libs/
folder, right-click each
.jar
file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the
android-support-v4.jar
and
android-support-v7-appcompat.jar
files to the build path.
Right-click the library project folder and select Build Path > Configure Build Path.
In the Order and Export tab, check the
.jar
files you just added to the build path, so they are available to projects that depend on this library project. For example, the
appcompat
project requires you to export both the
android-support-v4.jar
and
android-support-v7-appcompat.jar
files.
Uncheck Android Dependencies.
Click OK to complete the changes.

You now have a library project for your selected Support Library that you can use with one or more application projects.
Add the library to your application project:
In the Project Explorer, right-click your project and select Properties.
In the category panel on the left side of the dialog, select Android.
In the Library pane, click the Add button.
Select the library project and click OK. For example, the
appcompat
project should be listed as android-support-v7-appcompat.
In the properties window, click OK.
Note: If you are using the
android-support-v7-mediarouter
support library, you should note that it depends on the
android-support-v7-appcompat
library. In order for the v7 mediarouter library to compile, you must import both library projects into your development workspace. Then follow the procedure above to add the v7 appcompat project as a library to the v7 mediarouter library project.
https://developer.android.com/tools/support-library/setup.html#add-library> 转载请注明。

来源: http://write.blog.csdn.net/mdeditor#!postId=45824833
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android
相关文章推荐