前言

引入公共库库(commonLib)时,出现如下异常,说实话,看不懂哈,就问谷歌了。

  1. Can't determine type for tag '<macro name="m3_comp_assist_chip_container_shape">?attr/shapeAppearanceCornerSmall</macro>'
复制

正文

简单记录一下,方便自己查阅。

第一种

原因

因为commonLib/build.gradle中的appcompat版本比我应用版本高。

  1. implementation 'androidx.appcompat:appcompat:1.6.1'
复制

应用

  1. implementation 'androidx.appcompat:appcompat:1.3.1'
复制
解决方法

改成统一的就行,公共库也是我自己维护,这里就改低版本。验证OK

  1. implementation 'androidx.appcompat:appcompat:1.3.1'
复制

第二种

这次是用Android Studio创建新模块出现问题。

下面是用的版本

  1. Android Studio Giraffe | 2022.3.1
  2. Build #AI-223.8836.35.2231.10406996, built on June 29, 2023
  3. Runtime version: 17.0.6+0-b2043.56-10027231 amd64
  4. VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
  5. Windows 7 6.1
  6. GC: G1 Young Generation, G1 Old Generation
  7. Memory: 1280M
  8. Cores: 4
  9. Registry:
  10.   external.system.auto.import.disabled=true
  11.   ide.text.editor.with.preview.show.floating.toolbar=false
复制

新创建模块后也是提示

  1. Can't determine type for tag '<macro name="m3_comp_assist_chip_container_shape">?attr/shapeAppearanceCornerSmall</macro>'
复制

其实两个问题的本质都是一样,模块/build.gradle中配置的版本太高了。

下面都是AS默认创建的

  1. implementation 'androidx.appcompat:appcompat:1.6.1'
  2. implementation 'com.google.android.material:material:1.8.0'
  3. implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
复制

下面是我这边改的

第一步

版本降低

  1. implementation 'androidx.appcompat:appcompat:1.4.1'
  2. implementation 'com.google.android.material:material:1.4.0'
  3. implementation 'androidx.appcompat:appcompat:1.3.0'
复制

但material这个涉及主题样式,相关的也需要改一下。

第二步

修改目录: values/themes.xml

  1. <resources xmlns:tools="http://schemas.android.com/tools">
  2.   <!-- Base application theme. -->
  3.   <style name="Base.Theme.BiuMall" parent="Theme.Material3.DayNight.NoActionBar">
  4.       <!-- Customize your light theme here. -->
  5.       <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
  6.   </style>
  7.   <style name="Theme.BiuMall" parent="Base.Theme.BiuMall" />
  8. </resources>
复制

Material3是高版本的,我们配置的不支持这个,因此该为MaterialComponents

  1. <resources xmlns:tools="http://schemas.android.com/tools">
  2.   <!-- Base application theme. -->
  3.   <style name="Base.Theme.BiuMall" parent="Theme.MaterialComponents.DayNight.NoActionBar">
  4.       <!-- Customize your light theme here. -->
  5.       <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
  6.   </style>
  7.   <style name="Theme.BiuMall" parent="Base.Theme.BiuMall" />
  8. </resources>
复制
第三步

同样,夜模式主题也得修改。

修改目录: values-night/themes.xml

  1. <resources xmlns:tools="http://schemas.android.com/tools">
  2.   <!-- Base application theme. -->
  3.   <style name="Base.Theme.BiuMall" parent="Theme.Material3.DayNight.NoActionBar">
  4.       <!-- Customize your dark theme here. -->
  5.       <!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
  6.   </style>
  7. </resources>
复制

修改后

  1. <resources xmlns:tools="http://schemas.android.com/tools">
  2.   <!-- Base application theme. -->
  3.   <style name="Base.Theme.BiuMall" parent="Theme.MaterialComponents.DayNight.NoActionBar">
  4.       <!-- Customize your dark theme here. -->
  5.       <!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
  6.   </style>
  7. </resources>
复制

参考文章

  1. 【Android studio错误处理】Can‘t determine type for tag ‘<macro name=“m3_comp_assist_chip_container_shape“>

相关文章

暂无评论

none
暂无评论...