You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 8迁Android 10构建报错:无法识别shapeAppearanceCornerSmall标签类型

Android 8迁移至Android 10构建失败问题解决

问题概述

将代码从Android 8迁移至Android 10后,构建持续失败,抛出错误:

"Can't determine type for tag ' attr/shapeAppearanceCornerSmall' Can't determine type for tag '?attr/shapeAppearanceCornerSmall'"

已尝试以下方案但未解决:

  • 参考Stack Overflow相关问题执行两个解决方案,错误未消除且新增其他错误
  • 在XML文件中定义macro,问题依旧存在

相关代码

AndroidManifest.xml

<!-- Define the macro -->
<macro android:name="m3_comp_assist_chip_container_shape"
    tools:ignore="ExtraText">?attr/shapeAppearanceCornerSmall</macro>

<!-- Use the macro -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="@m3_comp_assist_chip_container_shape">

Build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29

    defaultConfig {
        externalNativeBuild {
            cmake {
                cppFlags "-fstack-protector-all"
            }
        }

        minSdkVersion 19
        //  targetSdkVersion 29

        applicationId "com.dcpl.printfromonbase"

        versionName "2.2"
        versionCode 6

        // Enabling multidex support.
        multiDexEnabled true
    }

    repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            debuggable false
        }

        customDebuggableBuildType {
            debuggable false
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            debuggable false
            signingConfig signingConfigs.debug
        }
    }
}

dependencies {
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support.constraint:constraint-layout:2.0.4'
    //noinspection GradleCompatible
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'
    implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
    //noinspection GradleCompatible
    implementation 'com.android.support:design:28.0.0'
    implementation 'androidx.annotation:annotation:1.5.0'
    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    implementation 'com.google.android.material:material:1.8.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'junit:junit:4.13.2'
    implementation 'android.arch.persistence.room:runtime:1.1.1'
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
    implementation project(path: ':WorkpathLib')
    implementation 'androidx.preference:preference:1.2.0'
    implementation 'org.lucasr.twowayview:twowayview:0.1.4'
    implementation 'com.android.volley:volley:1.2.1'
}

问题分析与修复方案

核心问题

  1. 新旧依赖库冲突:同时混用com.android.support(旧Support库)和androidx(Jetpack库),导致资源属性识别冲突,shapeAppearanceCornerSmall属于Material Components库,新旧库共存会引发属性解析错误。
  2. Shape属性使用错误:android:shape需要指定形状类型(如rectangle、oval),你用macro引用的是圆角大小属性,属于概念误用。
  3. 编译版本不匹配:com.google.android.material:material:1.8.0要求compileSdkVersion至少为33,当前设置为29(Android 10),版本不兼容。

修复步骤

  1. 统一依赖为AndroidX
    删除所有com.android.support相关依赖,替换为对应AndroidX库:

    // 替换后的依赖片段
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.room:room-runtime:2.5.0'
    annotationProcessor 'androidx.room:room-compiler:2.5.0'
    

    保留已存在的androidx.appcompat:appcompat:1.6.0、androidx.constraintlayout:constraintlayout:2.1.4、com.google.android.material:material:1.8.0。

  2. 更新编译版本
    修改android块中的版本配置:

    android {
        compileSdkVersion 33
        defaultConfig {
            targetSdkVersion 33 // 或保持29,建议同步到33
            // ...其他配置
        }
        // ...其他配置
    }
    
  3. 修正Shape与Macro使用
    删除Manifest中的错误macro定义,正确使用shape和圆角属性:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:radius="?attr/shapeAppearanceCornerSmall" />
    </shape>
    
  4. 清理缓存并重新构建
    执行命令清理构建缓存后重新编译:

    ./gradlew clean
    ./gradlew assembleDebug
    

内容的提问来源于stack exchange,提问作者Albin Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 23:20:42