Can't Find Theme.AppCompat.Light for New Andro

2018-12-31 10:23发布

I am trying to implement the new ActionBar support library that was released by Google a couple days ago. In the past, I have successfully implemented ActionBarSherlock without any issues using the same method listed on Google Developer's Support Library Setup page - using the guide on how to include the resources (which is similar to how ActionBarSherlock did it). I have the library project loaded in to my own project as a library as well.

I can tell the library is loading fine. When, instead of extending Activity on my MainActivity.java, I changed it to extend ActionBarActivity (as per Google's instructions), no errors occur - and it imports correctly.

I even tried bypassing the style.xml file and adding @style/Theme.AppCompat.Light directly in to the AndroidManifest.xml for both <application> and <activity> with android:theme="@style/ThemeAppCompat.Light" with all attempts resulting in the same error.

Now the issue is I cannot get it to change the theme, let alone even build without throwing an error. Below is the error I am receiving, followed by the style.xml file I changed to use the new theme.

I have moderate experience working with Android apps and am running Eclipse with the latest version of the Support Libraries and SDK compiling with API 18 (Android 4.3).

Error Received During Build

error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light'. styles.xml /ActBarTest/res/values line 3 Android AAPT Problem

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ProsoftStudio.ACTest" parent="@style/Theme.AppCompat.Light">
    </style>
</resources>

Any suggestions? This was never an issue with ActionBarSherlock. I want to work on using this new support library. It almost seems like the .jar is loading, but not the resources.

30条回答
何处买醉
2楼-- · 2018-12-31 10:46

This is an issue that can happen in Android Studio if you modify Project Structure Modules. In this case you may need to add the dependencies again. In a text editor edit the 'build.gradle' file to include the required dependencies:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

This should update your '{your_project_name}.iml' file with lib components:

<orderEntry type="library" exported="" name="appcompat-v7-19.0.1" level="project" />
查看更多
残风、尘缘若梦
3楼-- · 2018-12-31 10:46

My issue resolve via following Steps

  1. File->Import (android-sdk\extras\android\support\v7\appcompat)
  2. Right Click Project-> properties->Android. In the section library "Add" and choose library appcompat that's include in step 1
  3. Delete all files from project's libs directory
  4. add following file to project's libs directory <SDK-PATH>\extras\android\support\v13android-support-v13.jar

    Restart Eclipse if required. That's it. Your problem should be disappeared.

查看更多
萌妹纸的霸气范
4楼-- · 2018-12-31 10:48

I did the following in Eclipse with the Android Support Library (APL) project and the Main Project (MP):

  1. Ensured both APL and MP had the same minSdkVersion and targetSdkVersion.

  2. Added APL as a build dependency for MP:

    1. Going into "Properties > Java Build Path" of MP, and then

    2. Selecting the "Projects" tab and adding APL.

  3. In the properties of MP, under "Android", added a reference to APL under library.

1 and 2 got the references to Java classes working fine...however I still saw the error in the manifest.xml for MP when trying to reference @style/Theme.AppCompat.Light from APL. This only went away when I performed step 3.

查看更多
只若初见
5楼-- · 2018-12-31 10:48

It happened to me when Eclipse(Luna)/AndroidSDK(not Android Stduio) were used with the latest tools and library as of Jan. 14, 2015 during the project like HelloWorld. When I installed those tools and made HelloWorld the first app, I accepted all the defaults. - This is the problem in my case.

First, check whether or not the "Android Support Library" library is installed. If not, install it. It is not installed by default. You may do it all in "Android SDK manager" available in the menu.

(Android SDK Manager -> Extra -> Android Support Library)

Blessings, (a debtor)<><

查看更多
宁负流年不负卿
6楼-- · 2018-12-31 10:53

I will share my experience with this problem. I was going crazy because of this, but I found out that the problem was a bug with Eclipse itself, rather than my code: In eclipse, unable to reference an android library project in another android project

So, if you have the Android Support Library in your C: drive and your project in the D: drive on your computer, Eclipse won't function correctly and won't know where the Android Support Library is (green tick turns into red cross). To solve this, you need to move both projects onto the same hard drive.

查看更多
墨雨无痕
7楼-- · 2018-12-31 10:56

If, like me, you are following the Android tutorial on http://developer.android.com/training/basics/actionbar/setting-up.html and keep getting this error, try to change the AppBaseTheme style in all styles.xml files. In detail:

  1. In file res/values/styles.xml change the line:

    <style name="AppBaseTheme" parent="android:Theme.Light">
    

    to:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    
  2. In file res/values-v11/styles.xml change the line:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    

    to:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    
  3. In file res/values-v14/styles.xml change the line:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    

    to:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    

Now the application should run fine.

查看更多
登录 后发表回答