首页 > 解决方案 > Android Studio 无法识别 appcompat 或任何其他默认项

问题描述

今天,我重新打开了一个应用程序(几个月后),几个月前我曾在该应用程序上工作过。但不幸的是,对于该应用程序的代码,一切似乎都停止工作了。我已经通过互联网搜索了各种黑客如何解决appcompatactivity not resolved

rTheme.AppCompat.Light.DarkActionBar not recognized

但我似乎完全结合了所有最奇怪的错误..

这是我从 Android Studio 收到的礼物——

java compiler errors(14 errors)
resource style/Animation.AppCompat.Dialog (aka com.actech.android.frienchat:style/Animation.AppCompat.Dialog) not found.    
resource style/Theme.AppCompat.Light.DarkActionBar (aka com.actech.android.frienchat:style/Theme.AppCompat.Light.DarkActionBar) not found.  
resource style/TextAppearance.AppCompat (aka com.actech.android.frienchat:style/TextAppearance.AppCompat) not found.    
resource style/Base.V7.Theme.AppCompat.Dialog (aka com.actech.android.frienchat:style/Base.V7.Theme.AppCompat.Dialog) not found.    
resource style/Base.V7.Theme.AppCompat.Light.Dialog (aka com.actech.android.frienchat:style/Base.V7.Theme.AppCompat.Light.Dialog) not found.    
resource style/Base.V7.ThemeOverlay.AppCompat.Dialog (aka com.actech.android.frienchat:style/Base.V7.ThemeOverlay.AppCompat.Dialog) not found.  
resource style/Base.V7.Theme.AppCompat (aka com.actech.android.frienchat:style/Base.V7.Theme.AppCompat) not found.  
resource style/Animation.AppCompat.Dialog (aka com.actech.android.frienchat:style/Animation.AppCompat.Dialog) not found.    
resource style/Theme.AppCompat.Light.DarkActionBar (aka com.actech.android.frienchat:style/Theme.AppCompat.Light.DarkActionBar) not found.  
resource style/TextAppearance.AppCompat (aka com.actech.android.frienchat:style/TextAppearance.AppCompat) not found.    
resource style/Base.V7.Theme.AppCompat.Dialog (aka com.actech.android.frienchat:style/Base.V7.Theme.AppCompat.Dialog) not found.    
resource style/Base.V7.Theme.AppCompat.Light.Dialog (aka com.actech.android.frienchat:style/Base.V7.Theme.AppCompat.Light.Dialog) not found.    
resource style/Base.V7.ThemeOverlay.AppCompat.Dialog (aka com.actech.android.frienchat:style/Base.V7.ThemeOverlay.AppCompat.Dialog) not found.  
resource style/Base.V7.Theme.AppCompat (aka com.actech.android.frienchat:style/Base.V7.Theme.AppCompat) not found.

首先,我想澄清一下,我已经尝试了以下这些技巧-

1.Clean-重建

2.Invalidate Cache-restart

3.删除.idea文件夹

4.删除构建文件夹

5.更改appcompat版本

没有任何效果

这是我的 build.gradle 文件-

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.actech.android.frienchat"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.google.firebase:firebase-database:16.0.4'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.firebase:firebase-storage:16.0.4'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.firebase:firebase-config:16.1.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    implementation 'com.github.chrisbanes:PhotoView:2.1.3'
    implementation 'com.android.support:cardview-v7:27.1.1'

}

build.gradle(Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

非常感谢任何帮助(它充分证明几个月前我在 android studio 上成功使用了这个 android 项目)

标签: androidandroid-studioandroid-gradle-pluginandroid-build

解决方案


好的,经过不同的尝试和错误,我找到了一个 FIX ,这应该是在没有任何工作时执行的最简单的方法!

使用默认设置启动一个新的 Android Studio 项目。

然后将新建项目的build.gradle(app and project)的通用内容复制替换到有问题的项目中,并同步

哪个应该解决所有这些类型的错误(但请确保您已经尝试过问题中提到的黑客 - 这对我来说失败了并且被迫找到这个新的解决方案..

希望这对将来面临任何这些问题的任何其他人有所帮助。


推荐阅读