【问题标题】:Gradle build: resource android:style/TextAppearance.Material not foundGradle 构建:资源 android:style/TextAppearance.Material 未找到
【发布时间】:2018-06-01 11:13:49
【问题描述】:

我刚刚安装了 AndroidStudio 并导入了一个旧的 Eclipse ADT 项目(API 级别 18)。但是,当尝试在 AndroidStudio 中构建此项目时,我收到以下错误:

resource android:style/TextAppearance.Material not found.   
resource android:style/TextAppearance.Material.Body1 not found. 
resource android:style/TextAppearance.Material.Body2 not found. 
resource android:style/TextAppearance.Material.Button not found.    
resource android:style/TextAppearance.Material.Caption not found.   
resource android:style/TextAppearance.Material.Display1 not found.  
resource android:style/TextAppearance.Material.Display2 not found.  
resource android:style/TextAppearance.Material.Display3 not found.  
resource android:style/TextAppearance.Material.Display4 not found.  
resource android:style/TextAppearance.Material.Headline not found.  
resource android:style/TextAppearance.Material.Inverse not found.   
resource android:style/TextAppearance.Material.Large not found. 
resource android:style/TextAppearance.Material.Large.Inverse not found. 
resource android:style/TextAppearance.Material.Widget.PopupMenu.Large not found.    
resource android:style/TextAppearance.Material.Widget.PopupMenu.Small not found.    
resource android:style/TextAppearance.Material.Medium not found.    
resource android:style/TextAppearance.Material.Medium.Inverse not found.    
resource android:style/TextAppearance.Material.Menu not found.  
resource android:style/TextAppearance.Material.SearchResult.Subtitle not found. 
resource android:style/TextAppearance.Material.SearchResult.Title not found.    

如何解决此错误?我应该提供哪些进一步的信息?

这是导入协议,以防万一:

ECLIPSE ANDROID PROJECT IMPORT SUMMARY
======================================

Manifest Merging:
-----------------
Your project uses libraries that provide manifests, and your Eclipse
project did not explicitly turn on manifest merging. In Android Gradle
projects, manifests are always merged (meaning that contents from your
libraries' manifests will be merged into the app manifest. If you had
manually copied contents from library manifests into your app manifest
you may need to remove these for the app to build correctly.

Ignored Files:
--------------
The following files were *not* copied into the new Gradle project; you
should evaluate whether these are still needed in your project and if
so manually move them:

* .gitignore
* ic_launcher-web.png
* proguard-project.txt

Replaced Jars with Dependencies:
--------------------------------
The importer recognized the following .jar files as third party
libraries and replaced them with Gradle dependencies instead. This has
the advantage that more explicit version information is known, and the
libraries can be updated automatically. However, it is possible that
the .jar file in your project was of an older version than the
dependency we picked, which could render the project not compileable.
You can disable the jar replacement in the import wizard and try again:

android-support-v4.jar => com.android.support:support-v4:18.0.0

Replaced Libraries with Dependencies:
-------------------------------------
The importer recognized the following library projects as third party
libraries and replaced them with Gradle dependencies instead. This has
the advantage that more explicit version information is known, and the
libraries can be updated automatically. However, it is possible that
the source files in your project were of an older version than the
dependency we picked, which could render the project not compileable.
You can disable the library replacement in the import wizard and try
again:

google-play-services_lib => [com.google.android.gms:play-services:+]

Moved Files:
------------
Android Gradle projects use a different directory structure than ADT
Eclipse projects. Here's how the projects were restructured:

* AndroidManifest.xml => app\src\main\AndroidManifest.xml
* assets\ => app\src\main\assets
* libs\commons-net-3.3.jar => app\libs\commons-net-3.3.jar
* res\ => app\src\main\res\
* src\ => app\src\main\java\

Next Steps:
-----------
You can now build the project. The Gradle project needs network
connectivity to download dependencies.

Bugs:
-----
If for some reason your project does not build, and you determine that
it is due to a bug or limitation of the Eclipse to Gradle importer,
please file a bug at http://b.android.com with category
Component-Tools.

(This import summary is for your information only, and can be deleted
after import once you are satisfied with the results.)

【问题讨论】:

  • resource android:style/TextAppearance.Material not found 的可能重复项。如果它不能解决您的问题,请发布您的 .gradle 文件。
  • 请在您的项目中添加您的 style.xml 内容和库列表
  • @stefan.at.wpf 看看我的回答,你的 SDK 版本应该和支持库匹配。

标签: android android-studio android-gradle-plugin


【解决方案1】:

您的编译 SDK 版本必须支持库匹配。所以这是一个最新版本的例子。使用您的类似操作或更新到最新版本(推荐),如下所示:

1.在你的Build.gradle更改:

implementation 'com.android.support:appcompat-v7:28.0.0'

2.将compileSdkVersion和buildToolsVersion改为:

compileSdkVersion 28
buildToolsVersion "28.0.3"

3.更新项目gradle文件:

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

我建议您将项目中的所有依赖项更新为最新版本,如果您向我们提供 gradle 文件,我会为您提供更多帮助。希望对您有所帮助。

【讨论】:

  • 还要确保检查所有库模块
  • 谢谢,那没有编译,但显示了易于理解的错误。我是例如使用已弃用的 GooglePlayServicesClient。将迁移到 GoogleApi。接受这个作为答案,因为它对我有帮助。
  • 另外,如果您有意使用旧版本的小部件,请从应用程序 build.gradle 文件的“依赖项”块中删除引用“androidx”的“实现”。编辑布局 .xml 文件可能会导致 AndroidStudio 将这些行添加到您的 build.gradle 文件中。
【解决方案2】:

您也可以尝试在 android studio 中清理项目。有时这会有所帮助。

Build -> Rebuild Project

【讨论】:

  • 谢谢,值得一试,但没有帮助。
【解决方案3】:

确保你的依赖项中有这个:

  • 如果您使用的是 androidx

implementation 'com.google.android.material:material:1.0.0'

  • 其他

implementation 'com.android.support:design:28.0.0'

此外,请检查您的应用程序的 gradle 文件,如果它在 repositories 部分下包含 google()

allprojects {
    repositories {
      google()
      jcenter()
    }
  }

更多详情请见https://material.io/develop/android/docs/getting-started/

【讨论】:

    【解决方案4】:

    看看this,可能是支持库没有被导入的问题

    【讨论】:

      【解决方案5】:

      首先你必须添加require依赖到builde.gradle(模块):

      implementation 'com.google.android.material:material:1.1.0'
      

      接下来,将style.xml 中的 AppStyle 更改为:

      style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"
      

      希望能解决你的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-07
        • 1970-01-01
        • 2020-03-15
        • 1970-01-01
        • 2020-03-06
        • 2016-03-26
        • 1970-01-01
        相关资源
        最近更新 更多