IDE “Cannot Resolve @style/Theme.Appcompat” when u

2019-01-22 05:30发布

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.

12条回答
闹够了就滚
2楼-- · 2019-01-22 06:18

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.

查看更多
聊天终结者
3楼-- · 2019-01-22 06:21

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'
    
查看更多
Rolldiameter
4楼-- · 2019-01-22 06:22

I changed from:

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

to:

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

and now it's working!

查看更多
Bombasti
5楼-- · 2019-01-22 06:23

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

查看更多
做个烂人
6楼-- · 2019-01-22 06:24

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'
    }
查看更多
欢心
7楼-- · 2019-01-22 06:28

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 
查看更多
登录 后发表回答