本文主要以OSChina【开源中国】的代码为例说明一下两个问题的解决方法:
<1>error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCom
<2>R.java无法生成
1. 错误说明
AppCompat
is a library project. You need to reference the library project in your android project.
To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:
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>/ /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 theandroid-support-v4.jar
andandroid-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, theappcompat
project requires you to export both theandroid-support-v4.jar
andandroid-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 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.
下面我用更直观一点的图文的形式说明以下我的做法:
1. 打开SDk maneger 更新sdk中的 support文件:
1. File-》import-》Exisiting Android Code Into Workspace
点击Browse ,然后按照【 <sdk>/extras/android/support/v7/appcompat/
】(<sdk>表示自己放sdk的路径),选中appcompat,然后确定,点击finish完成导入。导入之后发现android-support-v7-appcompat这个project也会报错:
我找的解决方法如下:
When using the v7-appcompat
in Eclipse you have to use it as a library project. It isn't enough to just copy the *.jar to your /libs
folder. Please read this (click) step-by-step tutorial ondeveloper.android.com in order to know how to import the project properly.
As soon as the project is imported, you'll realize that some folders in the /res
folder are red-underlined because of errors such as the following:
error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.*'
error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Solution
The only thing you have to do is to open the project.properties
file of the android-support-v7-appcompat
and change the target from target=android-19
to target=android-21
.
Afterwards just do a Project --> Clean...
so that the changes take effect.
按照上边的说法处理之后,android-support-v7-appcompat的错误解决了:
点击add,选中Android-support-v7-appcompat然后OK
通过点击UP把Android-support-v7-appcompat移到第一位:
点击OK;
至此error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.问题解决。
同时R.java也能自动完成了:
/************************************************************************************************************************************
********************************* 本人也还只是菜鸟一个,抱着互相学习的态度分享自己的代码学习之路*********************
******************************** 文章中若有什么错误之处,还望各路大神吐槽指出 * *****************************