41

This is not really a huge issue, as my project still builds and runs correctly (using gradle), but I'm having trouble getting Android Studio to recognize the application compatibility theme released in the API 18 SDK (for allowing actionbar support for android 2.1 and above).

I have the support libraries loading successfully, because code completion is possible for the ActionBar classes in java files. The issue is that Android studio shows red text errors for assignments to the Theme.AppCompat.Light in the AndroidManifest.xml.

Is there a way to enable code completion for theme resources declared in the manifest from external libraries in Android Studio?

Updated Here is my <activity> block from my AndroidManifest:

<activity
    android:name="com.example.activities.MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/Theme.AppCompat.Light" >

I've also tried setting the theme in the application block:

<application
    android:allowBackup="true"
    android:icon="@drawable/main_final_ic"
    android:label="@string/app_name"
    android:logo="@drawable/main_final_enzo"
    android:theme="@style/Theme.AppCompat.Light" >

Again, these both work and compile OK, but appear as red text with errors in my IDE. I've also just confirmed that the same issues are occurring when running my project in eclipse.

sites
  • 21,417
  • 17
  • 87
  • 146
John Leehey
  • 22,052
  • 8
  • 61
  • 88
  • can you post your Manifest file where you set AppCompat theme? – Sharjeel Jul 25 '13 at 23:44
  • @Sharj I've added the portions of my manifest where the styles are set. Again, everything compiles OK, and replacing the appcompat styles with my custom styles works fine with autocomplete. – John Leehey Jul 26 '13 at 13:42
  • Hmmm, I'm pretty sure Studio should be picking up the resources from aar libraries. You've just added it as `compile` dependency on the artifact in the built-in repository, right? – Delyan Jul 26 '13 at 13:46
  • Right, the gradle files are pulling it from my local maven repository (loaded with the SDK manager). To get my java files working with autocomplete though, I had to explicitly add the v7 support jar to my build path... do you think that could be the issue? – John Leehey Jul 26 '13 at 13:58
  • I had to manually add the v7 support jar to my build path in Android Studio too, I also did the answer below to get it to 'resolve' the missing theme. – kev Jul 26 '13 at 15:22
  • I had a similar problem, which was fixed by: http://stackoverflow.com/a/30134839/513038 – Erhannis Jul 20 '16 at 22:03

13 Answers13

16

I had this same issue. Sounds like you have the V7 jar file compiling fine but you are probably missing the xml resource needed.You need to manually include the 'Theme.xml' provided with the V7 package. Here is what I did to fix it.

Look under:Adding libraries with resources http://developer.android.com/tools/support-library/setup.html

The directions provided here aren't very clear because it doesn't tell you to bring any resources in. (maybe a bug in Android Studio?)

Here is what I did:

  1. Update your SDK in the manager and be sure to include 'Android support repository' in extra's
  2. Go to SDK in file explorer (Finder on mac) track down the extra's folder (..\sdk\extras\android\support\v7\appcompat\res\values on Windows). Somewhere in there is a "themes.xml" and "themes_base.xml'. Copy both of these files.
  3. In your project paste the files into 'values' directory
  4. do a rebuilt and that did the trick for me.
Jim G.
  • 15,141
  • 22
  • 103
  • 166
kev
  • 2,306
  • 3
  • 26
  • 31
  • 6
    This causes additional errors, because those themes themselves reference other xml entries. Also, I'd rather not have 2 versions of the same theme available to my project, if possible. – John Leehey Jul 26 '13 at 18:58
  • I added a final step and it worked : 5. change styles.xml : –  Nov 23 '13 at 12:59
  • 1
    In my case, project compiles well, but I still have this : cannot resolves symbole "Theme" : "@style/Theme.AppCompat.Light.DarkActionBar" Theme is Red, but when I tip, ctrl+space suggest me this : "Theme.AppCompat.Light.DarkActionBar" and it compiles too but Theme is still in red... – Cocorico Aug 07 '14 at 09:37
  • This is by far the best guide someone can give others. Cause this works in Intellij Idea as well – Ghasem Jan 31 '16 at 08:51
  • @AlexJolig Intellij is the same program as Android Studio. – forresthopkinsa Jun 12 '17 at 21:32
7

I changed from:

classpath 'com.android.tools.build:gradle:+'

to:

classpath 'com.android.tools.build:gradle:2.2.3'

and now it's working!

zx485
  • 28,498
  • 28
  • 50
  • 59
SUXA
  • 169
  • 3
  • 14
  • 1
    Thanks. The problem shows up with `classpath 'com.android.tools.build:gradle:2.3.0-beta1'` while `2.2.3` works great. (Android Studio 2.2.3) – TalkLittle Jan 09 '17 at 21:40
4

This problem was fixed in Android Studio v0.2.7.

Yuichi Araki
  • 3,438
  • 1
  • 19
  • 24
4

Filip Cvejic's answer is useful. My android studio version is 1.3.1, has the same issue. It works after add one line "compile 'com.android.support:appcompat-v7:23.0.0'" as following:

   dependencies {
        compile "com.android.support:support-v4:23.0.0"
        compile "com.android.support:support-v13:23.0.0"
        compile "com.android.support:cardview-v7:23.0.0"
        compile 'com.android.support:appcompat-v7:23.0.0'
    }
XYL
  • 108
  • 5
3

Don't add the library to the Java Build Path, add the library (as a project) in Settings>Android>Libraries>Add Library.

3

Fix was simple for me on android studio.

Click help ---> Check for updates

Then actually read what the prompt says and decide whether you want a bleeding edge update or a stable update.

Once android studio restarts it should be working.

Side Note: Everything was still red underlined for me until I rebuilt the project.

rocktheartsm4l
  • 2,129
  • 23
  • 38
3

I know i replied late, but this answer might help futures visitors.

  • Change from Gradle 0.12.+ to 0.12.1 and it will works.

    classpath 'com.android.tools.build:gradle:0.12.1'
    
Luis Pena
  • 4,132
  • 2
  • 15
  • 23
2

Problem was that my appcompact library projest has been located in different location. On importing I have to check "Copy project into workspace" thats all!

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
2

Downgrading build:gradle version 2.3.3 to 2.2.3 worked after struggling for hours!

classpath 'com.android.tools.build:gradle:2.2.3'

gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
AskQ
  • 4,215
  • 7
  • 34
  • 61
1

A common problem. In my case this works:

In "android-support-v7-appcompat" project:

-Delete “android-support-v7-appcompat” from Package explorer.
-Import again and check “Copy into workspace”
-In Properties -> Android -> in Project build target, uncheck Android 2.2 and check Android 4.1.2
-In Java build path, uncheck if you have any .jar library, and uncheck the Dependences

In other hand, the proyect that uses “android-support-v7-appcompat”

in Propiedades -> Android add the library, but uncheck "IsLibrary”.
-In Android -> Project build tarjet check Android 4.0.
-In "Java Build Path" -> Order and Export -> Unchecked the .jar library
-Finally do a “Project -> Clean” both projects 
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32
1

Adding compile 'com.android.support:appcompat-v7:21.0.0' to dependencies in gradle.build (Module: app) and rebuilding the project fixed the problem for me in Android studio 1.0.2.

I also checked in SDK Manager and I did have the support libraries downloaded.

Filip Cvejic
  • 81
  • 1
  • 3
1

Problem was that my appcompact library projest has been located in different location. On importing I have to check "Copy project into workspace" thats all!

JUST go to Files click on close and then click on existing project and select your android project.... Theme issue will be resolved.

0

My fix/problem was much simpler and different than most people here.

My problem was similar in that I had an error like this:

resource style/ThemeOverlay.AppCompat.Dark (...) not found

The strange part was that I could build in debug mode, but not in release mode.

My Android Manifest contained no errors. My issue was that I had two style.xml files in my resources folder.

Simple Solution: Delete one of the style.xml files or merge them and you should be good. I had two styles that were almost exactly the same in my two .xml files. I could immediately build in release mode following the deletion of one of these files.

[%]D - Time to clink the glasses and drink some beer. :D

airvine
  • 631
  • 8
  • 23