java 如何在 android API 19 中使用 appcompat-v7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28149017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:05:15  来源:igfitidea点击:

How to use appcompat-v7 with android API 19

javaandroidcompatibilityandroid-5.0-lollipopandroid-appcompat

提问by An-droid

All is in the questioin

一切都在问题中

I have a module with this graddle :

我有一个带有这个 graddle 的模块:

apply plugin: 'com.android.library'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    compileOptions.encoding "ISO-8859-1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
}

When I change "compileSdkVersion" to 19 => I get 100+ errors about ressources not found :

当我将“compileSdkVersion”更改为 19 => 我收到 100 多个关于找不到资源的错误:

Example :

例子 :

    Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body1'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body2'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Button'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Caption'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display1'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display2'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display3'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display4'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Headline'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Menu'.
Error:Error retrieving parent for item: No resource found that matches the given name '@android:TextAppearance.Material.SearchResult.Subtitle'.
Error:Error retrieving parent for item: No resource found that matches the given name '@android:TextAppearance.Material.SearchResult.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Subhead'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Title'.

回答by snachmsm

of course you are getting these errors in API<21, because android:TextAppearance.Materialand others (Material) were introduced in API 21. AppCompat is porting resources, but they are used without android:prefix (I can't check at this moment if these you are using also, but probably yes). If you compile your app with API 21 and run on lower API device crashes will occur also

当然,您会在 API<21 中遇到这些错误,因为android:TextAppearance.MaterialAPI 21 中引入了其他(材料)。 AppCompat 正在移植资源,但它们使用时没有android:前缀(我目前无法检查您是否也在使用这些) ,但可能是)。如果您使用 API 21 编译您的应用程序并在较低的 API 设备上运行,也会发生崩溃

android:prefix refer to built-in params, which should be in all versions of supported APIs (minSDK). Material isn't present in pre-API21 systems

android:前缀指的是内置参数,它应该在支持的 API (minSDK) 的所有版本中。API21 之前的系统中不存在材料

回答by ARK

Check the compileSdkVersion in build.gradle

检查 build.gradle 中的 compileSdkVersion

eg.

例如。

    android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    dexOptions {
        javaMaxHeapSize "2g"
        //jumboMode true
    }
}

If you keep the latest, shouldnt give you headaches. Reason this happens is if there are multiple R files generated for the same library.

如果你保持最新,不应该让你头疼。发生这种情况的原因是为同一个库生成了多个 R 文件。