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

就是遇到这种报错时该怎么办:
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 导入

android v7支持包导入问题,Support Error的正确解决方法_第1张图片

必须注意:appcompat_v7和sdk下的appcompat中的文件夹是不完全一致的,至于为什么,俺也不清楚,有人知道么?
然后,在下图中有四个跟lib有关的地方

android v7支持包导入问题,Support Error的正确解决方法_第2张图片

——  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中
android v7支持包导入问题,Support Error的正确解决方法_第3张图片


最后,结论很明确,你需要的是那几个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:

  1. Make sure you have downloaded the Android Support Library using the SDK Manager.
  2. Create a library project and ensure the required JAR files are included in the project’s build path:
    1. Select File > Import.
    2. Select Existing Android Code Into Workspace and click Next.
    3. Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding theappcompat project, browse to /extras/android/support/v7/appcompat/.
    4. Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    5. 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.
    6. Right-click the library project folder and select Build Path > Configure Build Path.
    7. 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.
    8. Uncheck Android Dependencies.
    9. 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:

  1. In the Project Explorer, right-click your project and select Properties.
  2. In the category panel on the left side of the dialog, select Android.
  3. In the Library pane, click the Add button.
  4. Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
  5. 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 theandroid-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

你可能感兴趣的:(eclipse,android)