AndroidX迁移后<macro>标签类型无法识别错误求助
解决AndroidX迁移后的
m3_comp_assist_chip_container_shape错误 迁移AndroidX后出现如下编译错误:
Error: Can't determine type for tag '<macro name="m3_comp_assist_chip_container_shape">? attr/shapeAppearanceCornerSmall</macro>'
app模块build.gradle内容
apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' apply plugin: 'io.fabric' android { compileSdkVersion 33 defaultConfig { applicationId "com.sevenringscement.smart.android" minSdkVersion 23 targetSdkVersion 33 versionCode 44 versionName "4.4.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' externalNativeBuild { cmake { cppFlags "" } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardrules.pro' } } externalNativeBuild { cmake { path "CMakeLists.txt" } } signingConfigs { release { v2SigningEnabled true } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) //noinspection GradleCompatible implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.github.barteksc:android-pdf-viewer:2.8.2' // implementation 'com.github.chrisbanes:PhotoView:2.3.0' //noinspection GradleCompatible implementation 'androidx.recyclerview:recyclerview:1.0.0' //noinspection GradleCompatible implementation 'androidx.cardview:cardview:1.0.0' //noinspection GradleCompatible implementation 'androidx.legacy:legacy-support-v4:1.0.0' //noinspection GradleCompatible implementation 'com.google.android.material:material:1.6.0' implementation 'com.squareup.retrofit2:retrofit:2.4.0' implementation 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'com.squareup.retrofit2:converter-scalars:2.3.0' implementation 'com.github.d-max:spots-dialog:1.1@aar' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1' implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0' //Butter Knife implementation 'com.jakewharton:butterknife:10.2.3' implementation 'com.google.android.material:material:1.8.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' //searchableSpinner implementation 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1' implementation 'com.google.firebase:firebase-messaging:17.3.3' // Check for v11.4.2 or higher implementation 'com.google.firebase:firebase-core:16.0.4' // Add dependency implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.squareup.picasso:picasso:2.5.2' //implementation 'com.nbsp:materialfilepicker:1.9.1' implementation 'com.ramotion.foldingcell:folding-cell:1.2.1' }
根目录build.gradle内容
// Top-level build file where you can add configuration options common to all sub projects/modules. buildscript { repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:7.0.4' classpath 'com.google.gms:google-services:4.3.15' // Add dependency classpath 'io.fabric.tools:gradle:1.28.0' //classpath 'com.ramotion.foldingcell:folding-cell:1.2.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { // maven { url "https://jitpack.io" } google() jcenter() maven { url 'https://maven.google.com/' } } }
解决方案
- 清理重复依赖:删除app模块中
com.google.android.material:material:1.6.0的引用,只保留1.8.0版本,避免版本冲突。 - 升级AndroidX核心依赖:将依赖更新到与compileSdkVersion 33兼容的版本:
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.recyclerview:recyclerview:1.3.2' // 若项目仍需要v4兼容类,可保留legacy-support-v4,否则建议替换为更现代的fragment依赖 implementation 'androidx.fragment:fragment:1.5.6' - 升级Gradle插件:根目录build.gradle中,将
com.android.tools.build:gradle升级到7.4.2,适配Electric Eel版本的Android Studio。 - 处理第三方库冲突:对可能依赖旧Material版本的第三方库,排除其Material依赖,例如:
implementation ('com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1') { exclude group: 'com.google.android.material' } - 检查主题配置:确保应用主题继承自
Theme.MaterialComponents系列,而非旧的AppCompat主题,示例:<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <!-- 自定义主题属性 --> </style> - 清理缓存并重构:执行
File -> Invalidate Caches... -> Invalidate and Restart,然后重新构建项目。
内容的提问来源于stack exchange,提问作者Habibur Rahman
相关产品推荐
相关产品推荐

