Java 错误:找不到资源style/Animation.AppCompat.Dialog(又名com.example.myapplication:style/Animation.AppCompat.Dialog)

Java 错误:找不到资源style/Animation.AppCompat.Dialog(又名com.example.myapplication:style/Animation.AppCompat.Dialog),java,android,android-gradle-plugin,Java,Android,Android Gradle Plugin,我是Android新手,正在尝试用Android studio 3.3.2版开发hello应用程序。我正在尝试创建默认的导航活动项目及其在构建过程中出现的错误,如下所示 Android resource linking failed error: resource style/Animation.AppCompat.Dialog (aka com.example.myapplication:style/Animation.AppCompat.Dialog) not found. error: r

我是Android新手,正在尝试用Android studio 3.3.2版开发hello应用程序。我正在尝试创建默认的导航活动项目及其在构建过程中出现的错误,如下所示

Android resource linking failed
error: resource style/Animation.AppCompat.Dialog (aka com.example.myapplication:style/Animation.AppCompat.Dialog) not found.
error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.example.myapplication:style/Theme.AppCompat.Light.DarkActionBar) not found.
error: resource style/ThemeOverlay.AppCompat.Dark.ActionBar (aka com.example.myapplication:style/ThemeOverlay.AppCompat.Dark.ActionBar) not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:401: error: style attribute 'attr/windowActionBar (aka com.example.myapplication:attr/windowActionBar)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:402: error: style attribute 'attr/windowNoTitle (aka com.example.myapplication:attr/windowNoTitle)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v21\values-v21.xml:8: error: style attribute 'attr/windowActionBar (aka com.example.myapplication:attr/windowActionBar)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v21\values-v21.xml:9: error: style attribute 'attr/windowNoTitle (aka com.example.myapplication:attr/windowNoTitle)' not found.
error: resource style/ThemeOverlay.AppCompat.Light (aka com.example.myapplication:style/ThemeOverlay.AppCompat.Light) not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:416: error: resource style/Widget.AppCompat.ListView.Menu (aka com.example.myapplication:style/Widget.AppCompat.ListView.Menu) not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:417: error: resource style/Animation.AppCompat.DropDownUp (aka com.example.myapplication:style/Animation.AppCompat.DropDownUp) not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:421: error: style attribute 'attr/windowMinWidthMajor (aka com.example.myapplication:attr/windowMinWidthMajor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:422: error: style attribute 'attr/windowMinWidthMinor (aka com.example.myapplication:attr/windowMinWidthMinor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:425: error: style attribute 'attr/windowFixedWidthMajor (aka com.example.myapplication:attr/windowFixedWidthMajor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:426: error: style attribute 'attr/windowFixedWidthMinor (aka com.example.myapplication:attr/windowFixedWidthMinor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:427: error: style attribute 'attr/windowFixedHeightMajor (aka com.example.myapplication:attr/windowFixedHeightMajor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:428: error: style attribute 'attr/windowFixedHeightMinor (aka com.example.myapplication:attr/windowFixedHeightMinor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:431: error: style attribute 'attr/windowMinWidthMajor (aka com.example.myapplication:attr/windowMinWidthMajor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:432: error: style attribute 'attr/windowMinWidthMinor (aka com.example.myapplication:attr/windowMinWidthMinor)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:438: error: style attribute 'attr/actionBarPopupTheme (aka com.example.myapplication:attr/actionBarPopupTheme)' not found.
F:\MyApplication2\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:439: error: style attribute 'attr/actionBarWidgetTheme (aka com.example.myapplication:attr/actionBarWidgetTheme)' not found.
我有如下的gradle项目文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    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'
}
我能够导入和运行其他项目,但这给了我如上所述的错误

试试这个

文件->导入(android sdk\extras\android\support\v7)
。选择“AppCompat”
Project->properties->Android
。在库部分添加并选择“AppCompat”

如果上述方法无效,请尝试以下一种方法

首先检查您是否正在使用Androidx,然后执行以下操作

删除

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
添加此项

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha08'
签入您的
gradel.properties
这两行已添加,如果未添加,则添加这一行

android.useAndroidX=true
android.enableJetifier=true

然后,清理重建项目一次

AppCompat是一个库项目。您需要在android项目中引用库项目

  • 在项目的build.gradle文件中包含Google的Maven存储库

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    
    所有项目{ 存储库{ 谷歌() 如果您使用的Gradle版本低于4.1,则必须 而是使用: 马文{ url“” } } }

  • 对于要在其中使用支持库的每个模块,请在模块的build.gradle文件的dependencies块中添加该库。例如,要添加v7 core utils库,请添加以下内容:


  • 实现“com.android.support:support core-utils:28.0.0”

    你能看看这篇文章并检查它是否相关:从res/values/styles.xml添加你的styles.xml代码吗